PowerBuilder
PowerBuilder
Xero Get Invoices
See more Xero Examples
Get Xero company invoices.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_JsonToken
oleobject loo_Resp
oleobject loo_JsonResponse
string ls_Type
string ls_InvoiceID
string ls_InvoiceNumber
string ls_Reference
string ls_AmountDue
string ls_AmountPaid
string ls_AmountCredited
integer li_IsDiscounted
integer li_HasAttachments
integer li_HasErrors
string ls_ContactContactID
string ls_ContactName
integer li_ContactHasValidationErrors
string ls_DateString
string ls_Date
string ls_DueDateString
string ls_DueDate
string ls_LineAmountTypes
string ls_SubTotal
string ls_TotalTax
string ls_Total
string ls_UpdatedDateUTC
string ls_CurrencyCode
string ls_FullyPaidOnDate
string ls_CurrencyRate
integer j
integer li_Count_j
string ls_PaymentID
string ls_Amount
integer li_HasAccount
integer li_HasValidationErrors
string ls_CreditNoteID
string ls_CreditNoteNumber
string ls_ID
string ls_AppliedAmount
integer k
integer li_Count_k
string ls_Id
string ls_Status
string ls_ProviderName
string ls_DateTimeUTC
integer i
integer li_Count_i
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_JsonToken = create oleobject
li_rc = loo_JsonToken.ConnectToNewObject("Chilkat.JsonObject")
li_Success = loo_JsonToken.LoadFile("qa_data/tokens/xero-access-token.json")
if li_Success = 0 then
Write-Debug loo_JsonToken.LastErrorText
destroy loo_Http
destroy loo_JsonToken
return
end if
loo_Http.AuthToken = loo_JsonToken.StringOf("access_token")
// Replace the value here with an actual tenant ID obtained from this example:
// Get Xero Tenant IDs
loo_Http.SetRequestHeader("Xero-tenant-id","83299b9e-5747-4a14-a18a-a6c94f824eb7")
loo_Http.Accept = "application/json"
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Success = loo_Http.HttpNoBody("GET","https://api.xero.com/api.xro/2.0/Invoices",loo_Resp)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_JsonToken
destroy loo_Resp
return
end if
Write-Debug "Response Status Code: " + string(loo_Resp.StatusCode)
loo_JsonResponse = create oleobject
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat.JsonObject")
loo_JsonResponse.Load(loo_Resp.BodyStr)
loo_JsonResponse.EmitCompact = 0
Write-Debug loo_JsonResponse.Emit()
if loo_Resp.StatusCode <> 200 then
Write-Debug "Failed."
destroy loo_Http
destroy loo_JsonToken
destroy loo_Resp
destroy loo_JsonResponse
return
end if
// Sample output...
// (See the parsing code below..)
//
// Use the this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// {
// "Id": "bda1f62f-0d63-4178-8d54-e91fd226987a",
// "Status": "OK",
// "ProviderName": "Chilkat2222",
// "DateTimeUTC": "\/Date(1587210234493)\/",
// "Invoices": [
// {
// "Type": "ACCPAY",
// "InvoiceID": "0032f627-3156-4d30-9b1c-4d3b994dc921",
// "InvoiceNumber": "9871",
// "Reference": "",
// "Payments": [
// {
// "PaymentID": "22974891-3689-4694-9ee7-fd2ba917af55",
// "Date": "\/Date(1579737600000+0000)\/",
// "Amount": 148.50,
// "Reference": "Chq 409",
// "HasAccount": false,
// "HasValidationErrors": false
// }
// ],
// "CreditNotes": [
// ],
// "Prepayments": [
// ],
// "Overpayments": [
// ],
// "AmountDue": 0.00,
// "AmountPaid": 148.50,
// "AmountCredited": 0.00,
// "IsDiscounted": false,
// "HasAttachments": false,
// "HasErrors": false,
// "Contact": {
// "ContactID": "d6a384fb-f46f-41a3-8ac7-b7bc9e0b5efa",
// "Name": "Melrose Parking",
// "Addresses": [
// ],
// "Phones": [
// ],
// "ContactGroups": [
// ],
// "ContactPersons": [
// ],
// "HasValidationErrors": false
// },
// "DateString": "2020-01-15T00:00:00",
// "Date": "\/Date(1579046400000+0000)\/",
// "DueDateString": "2020-01-24T00:00:00",
// "DueDate": "\/Date(1579824000000+0000)\/",
// "Status": "PAID",
// "LineAmountTypes": "Exclusive",
// "LineItems": [
// ],
// "SubTotal": 135.00,
// "TotalTax": 13.50,
// "Total": 148.50,
// "UpdatedDateUTC": "\/Date(1221560931500+0000)\/",
// "CurrencyCode": "AUD",
// "FullyPaidOnDate": "\/Date(1579737600000+0000)\/"
// },
// {
// "Type": "ACCPAY",
// "InvoiceID": "673dd7cc-beb7-4697-83d4-0c47cb400cc2",
// "InvoiceNumber": "",
// "Reference": "",
// "Payments": [
// {
// "PaymentID": "4d06f609-5200-4364-9c8b-d4379a945252",
// "Date": "\/Date(1580688000000+0000)\/",
// "Amount": 974.60,
// "Reference": "DD # 96013",
// "HasAccount": false,
// "HasValidationErrors": false
// }
// ],
// "CreditNotes": [
// {
// "CreditNoteID": "7df8949c-b71f-40c0-bbcf-39f2f450f286",
// "CreditNoteNumber": "03391",
// "ID": "7df8949c-b71f-40c0-bbcf-39f2f450f286",
// "HasErrors": false,
// "AppliedAmount": 218.90,
// "DateString": "2020-01-29T00:00:00",
// "Date": "\/Date(1580256000000+0000)\/",
// "LineItems": [
// ],
// "Total": 218.90
// }
// ],
// "Prepayments": [
// ],
// "Overpayments": [
// ],
// "AmountDue": 0.00,
// "AmountPaid": 974.60,
// "AmountCredited": 218.90,
// "IsDiscounted": false,
// "HasAttachments": false,
// "HasErrors": false,
// "Contact": {
// "ContactID": "d0cd2c4f-18a0-4f7c-a32a-2db00f29d298",
// "Name": "PC Complete",
// "Addresses": [
// ],
// "Phones": [
// ],
// "ContactGroups": [
// ],
// "ContactPersons": [
// ],
// "HasValidationErrors": false
// },
// "DateString": "2020-01-28T00:00:00",
// "Date": "\/Date(1580169600000+0000)\/",
// "DueDateString": "2020-02-04T00:00:00",
// "DueDate": "\/Date(1580774400000+0000)\/",
// "Status": "PAID",
// "LineAmountTypes": "Exclusive",
// "LineItems": [
// ],
// "SubTotal": 1085.00,
// "TotalTax": 108.50,
// "Total": 1193.50,
// "UpdatedDateUTC": "\/Date(1221561913790+0000)\/",
// "CurrencyCode": "AUD",
// "FullyPaidOnDate": "\/Date(1580688000000+0000)\/"
// },
// {
// "Type": "ACCPAY",
// "InvoiceID": "c12aff7e-12bf-4185-8702-460929f19674",
// "InvoiceNumber": "",
// "Reference": "",
// "Payments": [
// ],
// "CreditNotes": [
// ],
// "Prepayments": [
// ],
// "Overpayments": [
// ],
// "AmountDue": 2166.99,
// "AmountPaid": 0.00,
// "AmountCredited": 0.00,
// "CurrencyRate": 1.000000,
// "IsDiscounted": false,
// "HasAttachments": false,
// "HasErrors": false,
// "Contact": {
// "ContactID": "d0cd2c4f-18a0-4f7c-a32a-2db00f29d298",
// "Name": "PC Complete",
// "Addresses": [
// ],
// "Phones": [
// ],
// "ContactGroups": [
// ],
// "ContactPersons": [
// ],
// "HasValidationErrors": false
// },
// "DateString": "2020-04-10T00:00:00",
// "Date": "\/Date(1586476800000+0000)\/",
// "DueDateString": "2020-05-05T00:00:00",
// "DueDate": "\/Date(1588636800000+0000)\/",
// "Status": "AUTHORISED",
// "LineAmountTypes": "Exclusive",
// "LineItems": [
// ],
// "SubTotal": 1969.99,
// "TotalTax": 197.00,
// "Total": 2166.99,
// "UpdatedDateUTC": "\/Date(1497965301980+0000)\/",
// "CurrencyCode": "AUD"
// }
// ]
// }
//
ls_Id = loo_JsonResponse.StringOf("Id")
ls_Status = loo_JsonResponse.StringOf("Status")
ls_ProviderName = loo_JsonResponse.StringOf("ProviderName")
ls_DateTimeUTC = loo_JsonResponse.StringOf("DateTimeUTC")
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("Invoices")
do while i < li_Count_i
loo_JsonResponse.I = i
ls_Type = loo_JsonResponse.StringOf("Invoices[i].Type")
ls_InvoiceID = loo_JsonResponse.StringOf("Invoices[i].InvoiceID")
ls_InvoiceNumber = loo_JsonResponse.StringOf("Invoices[i].InvoiceNumber")
ls_Reference = loo_JsonResponse.StringOf("Invoices[i].Reference")
ls_AmountDue = loo_JsonResponse.StringOf("Invoices[i].AmountDue")
ls_AmountPaid = loo_JsonResponse.StringOf("Invoices[i].AmountPaid")
ls_AmountCredited = loo_JsonResponse.StringOf("Invoices[i].AmountCredited")
li_IsDiscounted = loo_JsonResponse.BoolOf("Invoices[i].IsDiscounted")
li_HasAttachments = loo_JsonResponse.BoolOf("Invoices[i].HasAttachments")
li_HasErrors = loo_JsonResponse.BoolOf("Invoices[i].HasErrors")
ls_ContactContactID = loo_JsonResponse.StringOf("Invoices[i].Contact.ContactID")
ls_ContactName = loo_JsonResponse.StringOf("Invoices[i].Contact.Name")
li_ContactHasValidationErrors = loo_JsonResponse.BoolOf("Invoices[i].Contact.HasValidationErrors")
ls_DateString = loo_JsonResponse.StringOf("Invoices[i].DateString")
ls_Date = loo_JsonResponse.StringOf("Invoices[i].Date")
ls_DueDateString = loo_JsonResponse.StringOf("Invoices[i].DueDateString")
ls_DueDate = loo_JsonResponse.StringOf("Invoices[i].DueDate")
ls_Status = loo_JsonResponse.StringOf("Invoices[i].Status")
ls_LineAmountTypes = loo_JsonResponse.StringOf("Invoices[i].LineAmountTypes")
ls_SubTotal = loo_JsonResponse.StringOf("Invoices[i].SubTotal")
ls_TotalTax = loo_JsonResponse.StringOf("Invoices[i].TotalTax")
ls_Total = loo_JsonResponse.StringOf("Invoices[i].Total")
ls_UpdatedDateUTC = loo_JsonResponse.StringOf("Invoices[i].UpdatedDateUTC")
ls_CurrencyCode = loo_JsonResponse.StringOf("Invoices[i].CurrencyCode")
ls_FullyPaidOnDate = loo_JsonResponse.StringOf("Invoices[i].FullyPaidOnDate")
ls_CurrencyRate = loo_JsonResponse.StringOf("Invoices[i].CurrencyRate")
j = 0
li_Count_j = loo_JsonResponse.SizeOfArray("Invoices[i].Payments")
do while j < li_Count_j
loo_JsonResponse.J = j
ls_PaymentID = loo_JsonResponse.StringOf("Invoices[i].Payments[j].PaymentID")
ls_Date = loo_JsonResponse.StringOf("Invoices[i].Payments[j].Date")
ls_Amount = loo_JsonResponse.StringOf("Invoices[i].Payments[j].Amount")
ls_Reference = loo_JsonResponse.StringOf("Invoices[i].Payments[j].Reference")
li_HasAccount = loo_JsonResponse.BoolOf("Invoices[i].Payments[j].HasAccount")
li_HasValidationErrors = loo_JsonResponse.BoolOf("Invoices[i].Payments[j].HasValidationErrors")
j = j + 1
loop
j = 0
li_Count_j = loo_JsonResponse.SizeOfArray("Invoices[i].CreditNotes")
do while j < li_Count_j
loo_JsonResponse.J = j
ls_CreditNoteID = loo_JsonResponse.StringOf("Invoices[i].CreditNotes[j].CreditNoteID")
ls_CreditNoteNumber = loo_JsonResponse.StringOf("Invoices[i].CreditNotes[j].CreditNoteNumber")
ls_ID = loo_JsonResponse.StringOf("Invoices[i].CreditNotes[j].ID")
li_HasErrors = loo_JsonResponse.BoolOf("Invoices[i].CreditNotes[j].HasErrors")
ls_AppliedAmount = loo_JsonResponse.StringOf("Invoices[i].CreditNotes[j].AppliedAmount")
ls_DateString = loo_JsonResponse.StringOf("Invoices[i].CreditNotes[j].DateString")
ls_Date = loo_JsonResponse.StringOf("Invoices[i].CreditNotes[j].Date")
ls_Total = loo_JsonResponse.StringOf("Invoices[i].CreditNotes[j].Total")
k = 0
li_Count_k = loo_JsonResponse.SizeOfArray("Invoices[i].CreditNotes[j].LineItems")
do while k < li_Count_k
loo_JsonResponse.K = k
k = k + 1
loop
j = j + 1
loop
j = 0
li_Count_j = loo_JsonResponse.SizeOfArray("Invoices[i].Prepayments")
do while j < li_Count_j
loo_JsonResponse.J = j
j = j + 1
loop
j = 0
li_Count_j = loo_JsonResponse.SizeOfArray("Invoices[i].Overpayments")
do while j < li_Count_j
loo_JsonResponse.J = j
j = j + 1
loop
j = 0
li_Count_j = loo_JsonResponse.SizeOfArray("Invoices[i].Contact.Addresses")
do while j < li_Count_j
loo_JsonResponse.J = j
j = j + 1
loop
j = 0
li_Count_j = loo_JsonResponse.SizeOfArray("Invoices[i].Contact.Phones")
do while j < li_Count_j
loo_JsonResponse.J = j
j = j + 1
loop
j = 0
li_Count_j = loo_JsonResponse.SizeOfArray("Invoices[i].Contact.ContactGroups")
do while j < li_Count_j
loo_JsonResponse.J = j
j = j + 1
loop
j = 0
li_Count_j = loo_JsonResponse.SizeOfArray("Invoices[i].Contact.ContactPersons")
do while j < li_Count_j
loo_JsonResponse.J = j
j = j + 1
loop
j = 0
li_Count_j = loo_JsonResponse.SizeOfArray("Invoices[i].LineItems")
do while j < li_Count_j
loo_JsonResponse.J = j
j = j + 1
loop
i = i + 1
loop
destroy loo_Http
destroy loo_JsonToken
destroy loo_Resp
destroy loo_JsonResponse