Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#This WebSession object was not generated by Postman but you will need it to
#Share the Session state across each of the ReST calls. These calls will not
#Work without it
$WebSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession
#We need this header data that Postman generated for us
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$body = "{`n `"name`":`"Admin`",`n `"password`":`"123`",`n `"tenant`":`"Company`"`n}"
$response = Invoke-RestMethod 'http://localhost/APS20_104_0012/entity/auth/login' -Method 'POST' -Headers $headers -Body $body -WebSession $WebSession
#Note: Postman incorrectly set the -Body $body parameter. It needs to be removed for this to work
$response = Invoke-RestMethod 'http://localhost/APS20_104_0012/entity/default/18.200.001/Invoice?$Filter=ReferenceNbr eq ''ReplaceWithRefNbrInYourSystem''' -Method 'GET' -Headers $headers -WebSession $WebSession
#Piping the The response to the ConvertTo-Json method will format the value and display to the output window
$response | ConvertTo-Json
$response = Invoke-RestMethod 'http://localhost/APS20_104_0012/entity/auth/logout ' -Method 'POST' -Headers $headers -Body $body -WebSession $WebSession
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.