Xbase++ Requires Chilkat v11.0.0+
Xbase++
Xero Get Invoices
See more Xero Examples
Get Xero company invoices.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oJsonToken
LOCAL oResp
LOCAL oJsonResponse
LOCAL cType
LOCAL cInvoiceID
LOCAL cInvoiceNumber
LOCAL cReference
LOCAL cAmountDue
LOCAL cAmountPaid
LOCAL cAmountCredited
LOCAL nIsDiscounted
LOCAL nHasAttachments
LOCAL nHasErrors
LOCAL cContactContactID
LOCAL cContactName
LOCAL nContactHasValidationErrors
LOCAL cDateString
LOCAL cDate
LOCAL cDueDateString
LOCAL cDueDate
LOCAL cLineAmountTypes
LOCAL cSubTotal
LOCAL cTotalTax
LOCAL cTotal
LOCAL cUpdatedDateUTC
LOCAL cCurrencyCode
LOCAL cFullyPaidOnDate
LOCAL cCurrencyRate
LOCAL j
LOCAL nCount_j
LOCAL cPaymentID
LOCAL cAmount
LOCAL nHasAccount
LOCAL nHasValidationErrors
LOCAL cCreditNoteID
LOCAL cCreditNoteNumber
LOCAL cID
LOCAL cAppliedAmount
LOCAL k
LOCAL nCount_k
LOCAL cId
LOCAL cStatus
LOCAL cProviderName
LOCAL cDateTimeUTC
LOCAL i
LOCAL nCount_i
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
oJsonToken := CreateObject("Chilkat.JsonObject")
nSuccess := oJsonToken:LoadFile("qa_data/tokens/xero-access-token.json")
IF (nSuccess == 0)
? oJsonToken:LastErrorText
oHttp:destroy()
oJsonToken:destroy()
RETURN
ENDIF
oHttp:AuthToken := oJsonToken:StringOf("access_token")
// Replace the value here with an actual tenant ID obtained from this example:
// Get Xero Tenant IDs
oHttp:SetRequestHeader("Xero-tenant-id", "83299b9e-5747-4a14-a18a-a6c94f824eb7")
oHttp:Accept := "application/json"
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpNoBody("GET", "https://api.xero.com/api.xro/2.0/Invoices", oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oJsonToken:destroy()
oResp:destroy()
RETURN
ENDIF
? "Response Status Code: " + Str(oResp:StatusCode)
oJsonResponse := CreateObject("Chilkat.JsonObject")
oJsonResponse:Load(oResp:BodyStr)
oJsonResponse:EmitCompact := 0
? oJsonResponse:Emit()
IF (oResp:StatusCode != 200)
? "Failed."
oHttp:destroy()
oJsonToken:destroy()
oResp:destroy()
oJsonResponse:destroy()
RETURN
ENDIF
// 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"
// }
// ]
// }
//
cId := oJsonResponse:StringOf("Id")
cStatus := oJsonResponse:StringOf("Status")
cProviderName := oJsonResponse:StringOf("ProviderName")
cDateTimeUTC := oJsonResponse:StringOf("DateTimeUTC")
i := 0
nCount_i := oJsonResponse:SizeOfArray("Invoices")
DO WHILE i < nCount_i
oJsonResponse:I := i
cType := oJsonResponse:StringOf("Invoices[i].Type")
cInvoiceID := oJsonResponse:StringOf("Invoices[i].InvoiceID")
cInvoiceNumber := oJsonResponse:StringOf("Invoices[i].InvoiceNumber")
cReference := oJsonResponse:StringOf("Invoices[i].Reference")
cAmountDue := oJsonResponse:StringOf("Invoices[i].AmountDue")
cAmountPaid := oJsonResponse:StringOf("Invoices[i].AmountPaid")
cAmountCredited := oJsonResponse:StringOf("Invoices[i].AmountCredited")
nIsDiscounted := oJsonResponse:BoolOf("Invoices[i].IsDiscounted")
nHasAttachments := oJsonResponse:BoolOf("Invoices[i].HasAttachments")
nHasErrors := oJsonResponse:BoolOf("Invoices[i].HasErrors")
cContactContactID := oJsonResponse:StringOf("Invoices[i].Contact.ContactID")
cContactName := oJsonResponse:StringOf("Invoices[i].Contact.Name")
nContactHasValidationErrors := oJsonResponse:BoolOf("Invoices[i].Contact.HasValidationErrors")
cDateString := oJsonResponse:StringOf("Invoices[i].DateString")
cDate := oJsonResponse:StringOf("Invoices[i].Date")
cDueDateString := oJsonResponse:StringOf("Invoices[i].DueDateString")
cDueDate := oJsonResponse:StringOf("Invoices[i].DueDate")
cStatus := oJsonResponse:StringOf("Invoices[i].Status")
cLineAmountTypes := oJsonResponse:StringOf("Invoices[i].LineAmountTypes")
cSubTotal := oJsonResponse:StringOf("Invoices[i].SubTotal")
cTotalTax := oJsonResponse:StringOf("Invoices[i].TotalTax")
cTotal := oJsonResponse:StringOf("Invoices[i].Total")
cUpdatedDateUTC := oJsonResponse:StringOf("Invoices[i].UpdatedDateUTC")
cCurrencyCode := oJsonResponse:StringOf("Invoices[i].CurrencyCode")
cFullyPaidOnDate := oJsonResponse:StringOf("Invoices[i].FullyPaidOnDate")
cCurrencyRate := oJsonResponse:StringOf("Invoices[i].CurrencyRate")
j := 0
nCount_j := oJsonResponse:SizeOfArray("Invoices[i].Payments")
DO WHILE j < nCount_j
oJsonResponse:J := j
cPaymentID := oJsonResponse:StringOf("Invoices[i].Payments[j].PaymentID")
cDate := oJsonResponse:StringOf("Invoices[i].Payments[j].Date")
cAmount := oJsonResponse:StringOf("Invoices[i].Payments[j].Amount")
cReference := oJsonResponse:StringOf("Invoices[i].Payments[j].Reference")
nHasAccount := oJsonResponse:BoolOf("Invoices[i].Payments[j].HasAccount")
nHasValidationErrors := oJsonResponse:BoolOf("Invoices[i].Payments[j].HasValidationErrors")
j := j + 1
ENDDO
j := 0
nCount_j := oJsonResponse:SizeOfArray("Invoices[i].CreditNotes")
DO WHILE j < nCount_j
oJsonResponse:J := j
cCreditNoteID := oJsonResponse:StringOf("Invoices[i].CreditNotes[j].CreditNoteID")
cCreditNoteNumber := oJsonResponse:StringOf("Invoices[i].CreditNotes[j].CreditNoteNumber")
cID := oJsonResponse:StringOf("Invoices[i].CreditNotes[j].ID")
nHasErrors := oJsonResponse:BoolOf("Invoices[i].CreditNotes[j].HasErrors")
cAppliedAmount := oJsonResponse:StringOf("Invoices[i].CreditNotes[j].AppliedAmount")
cDateString := oJsonResponse:StringOf("Invoices[i].CreditNotes[j].DateString")
cDate := oJsonResponse:StringOf("Invoices[i].CreditNotes[j].Date")
cTotal := oJsonResponse:StringOf("Invoices[i].CreditNotes[j].Total")
k := 0
nCount_k := oJsonResponse:SizeOfArray("Invoices[i].CreditNotes[j].LineItems")
DO WHILE k < nCount_k
oJsonResponse:K := k
k := k + 1
ENDDO
j := j + 1
ENDDO
j := 0
nCount_j := oJsonResponse:SizeOfArray("Invoices[i].Prepayments")
DO WHILE j < nCount_j
oJsonResponse:J := j
j := j + 1
ENDDO
j := 0
nCount_j := oJsonResponse:SizeOfArray("Invoices[i].Overpayments")
DO WHILE j < nCount_j
oJsonResponse:J := j
j := j + 1
ENDDO
j := 0
nCount_j := oJsonResponse:SizeOfArray("Invoices[i].Contact.Addresses")
DO WHILE j < nCount_j
oJsonResponse:J := j
j := j + 1
ENDDO
j := 0
nCount_j := oJsonResponse:SizeOfArray("Invoices[i].Contact.Phones")
DO WHILE j < nCount_j
oJsonResponse:J := j
j := j + 1
ENDDO
j := 0
nCount_j := oJsonResponse:SizeOfArray("Invoices[i].Contact.ContactGroups")
DO WHILE j < nCount_j
oJsonResponse:J := j
j := j + 1
ENDDO
j := 0
nCount_j := oJsonResponse:SizeOfArray("Invoices[i].Contact.ContactPersons")
DO WHILE j < nCount_j
oJsonResponse:J := j
j := j + 1
ENDDO
j := 0
nCount_j := oJsonResponse:SizeOfArray("Invoices[i].LineItems")
DO WHILE j < nCount_j
oJsonResponse:J := j
j := j + 1
ENDDO
i := i + 1
ENDDO
oHttp:destroy()
oJsonToken:destroy()
oResp:destroy()
oJsonResponse:destroy()