Last active
November 17, 2020 23:41
-
-
Save RobertWaiteREPAY/060e88e28fc5c349ce2a515ec248b872 to your computer and use it in GitHub Desktop.
PowerShellBlog010
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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