Public/Subscriptions.ps1

Function New-NmeLinkedSubscription {
    <#

    .SYNOPSIS

    Link Azure subscripiton.

    .DESCRIPTION

    Link Azure subscripiton.

    This function calls the /api/v1/subscriptions endpoint of the NME REST API, using the post method.


    .PARAMETER NmeLinkSubscriptionRestPayload

    Requires an NmeLinkSubscriptionRestPayload object, as generated by the New-NmeLinkSubscriptionRestPayload command.

    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$True)][ValidateScript({if ($_.PSObject.TypeNames -contains "NmeLinkSubscriptionRestPayload"){$true} else{throw " is not a NmeLinkSubscriptionRestPayload object."}})]$NmeLinkSubscriptionRestPayload
    )
    Set-NmeAuthHeaders
    Try {
        $json = $NmeLinkSubscriptionRestPayload | ConvertTo-Json -Depth 20
        Write-Debug 'json:'
        Write-Debug $json
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/subscriptions$QueryString" -Method post -Headers $script:AuthHeaders -ContentType 'application/json' -body $json
        Write-Verbose ($result | out-string)
        $Result.PSObject.TypeNames.Insert(0, 'NmeLinkedSubscriptionRestModel')
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}