Skip to content

Instantly share code, notes, and snippets.

"Create A payment for invoice $ReferenceNbr"
$body = @"
{
`"Type`": {`"value`": `"Payment`"},
`"CustomerID`": {`"value`": `"$CustomerNbr`"},
`"PaymentMethod`": {`"value`": `"$PaymentMethod`"},
`"PaymentAmount`": {`"value`": $UnitPrice},
`"DocumentsToApply`": [{`"ReferenceNbr`": {`"value`": `"$ReferenceNbr`"}}]
}
"@
Function Logout-Acumatica
{
param(
[Parameter(Mandatory=$true)]
[Microsoft.PowerShell.Commands.WebRequestSession]$WebSession,
$EndPoint = $env:AcumaticaTestEndPoint
)
$Uri = "$EndPoint/entity/auth/logout"
$response = Invoke-RestMethod $Uri -Method 'POST' -Headers $headers -WebSession $WebSession
#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")
$CustomerNbr = "ABARTENDE"
$Description = "This was auto created with PowerShell"
$InventoryID = "CONSULTING"
$Qty = "1.000000"
$UnitPrice = "100.000000"
$UOM = "HOUR"
#The @" and "@ tags declare a here string which allows you to have string declarations that run multiple lines
$body = @"
{
#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
"Releasing Invoice $ReferenceNbr"
$body = @"
{
`"entity`":{`"id`": `"$EntityID`"}
}
$body
"@
$HashArguments = @{
Uri = "$AcumaticaEndPoint/entity/default/18.200.001/Invoice/ReleaseInvoice"
Method = 'POST'
Function Login-Acumatica
{
#This OutputType allows you to strongly type the return object from this function
#In this case we are going to encapsulate the WebRequestSession object initialization and return it
#to the calling process as to be used in other functions. This is needed as to pass the authentication
#State to other functions that need it. Don’t forget to use the Logout-Acumatica function else you will incur
#unnecessary User Logins if they are left open.
[OutputType([Microsoft.PowerShell.Commands.WebRequestSession])]
param(
$User = $Null,
Function Get-Invoice
{
param(
[Parameter(Mandatory=$true)]
[Microsoft.PowerShell.Commands.WebRequestSession]$WebSession,
$EndPoint = $env:AcumaticaTestEndPoint,
[Parameter(Mandatory=$true)]
$ReferenceNbr)
$HashArguments = @{
Function Create-Invoice
{
param(
[Parameter(Mandatory=$true)]
[Microsoft.PowerShell.Commands.WebRequestSession]$WebSession,
$EndPoint = $env:AcumaticaTestEndPoint,
$Body,
[switch]$release)
$Uri = "$EndPoint/entity/default/18.200.001/Invoice"
Function Pay-Invoice
{
param(
[Parameter(Mandatory=$true)]
[Microsoft.PowerShell.Commands.WebRequestSession]$WebSession,
$EndPoint = $env:AcumaticaTestEndPoint,
[Parameter(Mandatory=$true)]
[string]$ReferenceNbr,
[Parameter(Mandatory=$true)]
[string]$PaymentMethod)