Last active
November 18, 2020 00:02
-
-
Save RobertWaiteREPAY/a94504240e05795a5c2b2571bb5ca976 to your computer and use it in GitHub Desktop.
PSBlog002
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
#We will declare Variable that will change often up at the top | |
#This is a common practice for scripts. | |
#Later we will convert this to a function, and these will become parameters | |
$AcumaticaUser = "Admin" | |
$AcumaticaPassword = "123" | |
$AcumaticaTenant = "Company" | |
$AcumaticaEndPoint = "http://localhost/APS20_104_0012" | |
$ReferenceNbr = "AR008403" | |
$WebSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession | |
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" | |
$headers.Add("Content-Type", "application/json") | |
#All we must do to format a string with variables is add the variable to the string. | |
#the ` grave char escapes so the `n are carriage returns. | |
$body = "{`n `"name`":`"$AcumaticaUser`",`n `"password`":`"$AcumaticaPassword`",`n `"tenant`":`"$AcumaticaTenant`"`n}" | |
$Uri = "$AcumaticaEndPoint/entity/auth/login" | |
$response = Invoke-RestMethod -Uri $Uri -Method 'POST' -Headers $headers -Body $body -WebSession $WebSession | |
#if you need to get the $ char into the string you can use `$ which will get it into place as we did here | |
# We also need to use the `' to get the single quote into the string | |
$Uri = "$AcumaticaEndPoint/entity/default/18.200.001/Invoice?`$Filter=ReferenceNbr eq `'$ReferenceNbr`'" | |
#Note: Post man incorrectly sets the -Body $body parameter. It needs to be removed for this to work with a get | |
$response = Invoke-RestMethod -Uri $Uri -Method 'GET' -Headers $headers -WebSession $WebSession | |
#Piping the response to the ConvertTo-Json method will format the value and | |
#display to the output window | |
$response | ConvertTo-Json | |
$Uri = "$AcumaticaEndPoint/entity/auth/logout" | |
$response = Invoke-RestMethod -Uri $Uri -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