(PowerShell) Xero Get Accounts using REST API
Demonstrates how to get the Accounts using the Chilkat REST library.
Note: Requires Chilkat v9.5.0.64 or greater.
Add-Type -Path "C:\chilkat\ChilkatDotNet47-9.5.0-x64\ChilkatDotNet47.dll"
# This requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
$rest = New-Object Chilkat.Rest
# Add the "Authorization: Bearer <token>" header.
$jsonToken = New-Object Chilkat.JsonObject
$success = $jsonToken.LoadFile("qa_data/tokens/xero-access-token.json")
if ($success -eq $false) {
$($jsonToken.LastErrorText)
exit
}
$sb = New-Object Chilkat.StringBuilder
$sb.Append("Bearer ")
$sb.Append($jsonToken.StringOf("access_token"))
$rest.Authorization = $sb.GetAsString()
$success = $rest.Connect("api.xero.com",443,$true,$true)
if ($success -eq $false) {
$($rest.LastErrorText)
exit
}
# Get the full list of accounts.
$sbXml = New-Object Chilkat.StringBuilder
$success = $rest.FullRequestNoBodySb("GET","/api.xro/2.0/Accounts",$sbXml)
if ($success -ne $true) {
$($rest.LastErrorText)
exit
}
# A 200 response is expected for actual success.
if ($rest.ResponseStatusCode -ne 200) {
$($sbXml.GetAsString())
exit
}
$($sbXml.GetAsString())
|