Skip to content

Instantly share code, notes, and snippets.

@RobertWaiteREPAY
Last active November 17, 2020 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertWaiteREPAY/060e88e28fc5c349ce2a515ec248b872 to your computer and use it in GitHub Desktop.
Save RobertWaiteREPAY/060e88e28fc5c349ce2a515ec248b872 to your computer and use it in GitHub Desktop.
PowerShellBlog010
#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