Invoke a HTTP Endpoint
Invoke a HTTP Endpoint and send a payload along
The URL endpoint that is capable of handling your request
The URL parameter has a default value if you have configured one with the designated functions
The raw (string) payload that you want to pass along to the HTTP Endpoint
Type parameter to instruct the HTTP Endpoint what kind of data that will be part of the request
.PARAMETER EnableException
This parameters disables user-friendly warnings and enables the throwing of exceptions.
This is less user friendly, but allows catching exceptions in calling scripts.
$hashTable = @{email = ""; subject = "More testing"; message = "I hope this finds you well"}
$payload = ($hashTable | ConvertTo-Json)
Invoke-PSNHttpEndpoint -Payload $payload -Url ""
This will invoke the HTTP endpoint and send along a payload. The payload comes from the HashTable that is converted into a Json object.
Author: Mötz Jensen (@Splaxi)

function Invoke-PSNHttpEndpoint {
    param (
        [string] $Url = (Get-PSNUrl).Url,

        [Parameter(Mandatory = $True)]
        [string] $Payload,

        [string] $Type = "Json",

        [switch] $EnableException
    begin {
        if (-not $Url) {
            Write-PSFMessage -Level Warning -Message "It seems that you didn't pass a URL and the module doesn't have a configured one to use."
            Stop-PSFFunction -Message "Stopping because of missing URL" -EnableException $EnableException
    process {
        if (Test-PSFFunctionInterrupt) {return}
        Write-PSFMessage -Level Verbose -Message "Prepping the details for executing the HTTP request."

        [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
        $request = [System.Net.WebRequest]::Create($Url)
        $request.Method = "POST"
        $request.ContentType = "application/$($Type.ToLower())";

        try {
            $stream = new-object System.IO.StreamWriter ($request.GetRequestStream())

            Write-PSFMessage -Level Verbose -Message "Executing the HTTP request."
            $response = $request.GetResponse()
            $requestStream = $response.GetResponseStream()
            $readStream = New-Object System.IO.StreamReader $requestStream
            $data = $readStream.ReadToEnd()
        catch {
            Write-PSFMessage -Level Verbose -Message "Something went wrong while contacting the http endpoint." -ErrorRecord $_
    end {