Xbase++ Requires Chilkat v11.0.0+
Xbase++
Xero Update Account Details
See more Xero Examples
Update some details of an account in a Xero company (Accounting API)Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oJsonToken
LOCAL oJsonRequestBody
LOCAL cUrl
LOCAL oResp
LOCAL oJsonResponse
LOCAL cAccountID
LOCAL cCode
LOCAL cName
LOCAL cType
LOCAL cTaxType
LOCAL cDescription
LOCAL cClass
LOCAL nEnablePaymentsToAccount
LOCAL nShowInExpenseClaims
LOCAL cReportingCode
LOCAL cReportingCodeName
LOCAL cUpdatedDateUTC
LOCAL nAddToWatchlist
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"
// The following JSON is sent in the request body:
// {
// "AccountID": "54ddab14-4a8d-45cf-86be-076c99a0cea0",
// "Name": "Sales account",
// "Type": "REVENUE",
// "TaxType": "OUTPUT",
// "Description": "Income from any normal business trading activity",
// "EnablePaymentsToAccount": "false",
// "ShowInExpenseClaims": "false"
// }
// Use this online tool to generate the code from sample JSON:
// Generate Code to Create JSON
oJsonRequestBody := CreateObject("Chilkat.JsonObject")
oJsonRequestBody:UpdateString("AccountID", "54ddab14-4a8d-45cf-86be-076c99a0cea0")
oJsonRequestBody:UpdateString("Name", "Sales account")
oJsonRequestBody:UpdateString("Type", "REVENUE")
oJsonRequestBody:UpdateString("TaxType", "OUTPUT")
oJsonRequestBody:UpdateString("Description", "Income from any normal business trading activity")
oJsonRequestBody:UpdateString("EnablePaymentsToAccount", "false")
oJsonRequestBody:UpdateString("ShowInExpenseClaims", "false")
cUrl := "https://api.xero.com/api.xro/2.0/Accounts/54ddab14-4a8d-45cf-86be-076c99a0cea0"
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("POST", cUrl, oJsonRequestBody, "application/json", oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oJsonToken:destroy()
oJsonRequestBody: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 >= 300)
? "Failed."
oHttp:destroy()
oJsonToken:destroy()
oJsonRequestBody: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": "430e92a8-de02-41d5-a00e-3ef899188aea",
// "Status": "OK",
// "ProviderName": "Chilkat2222",
// "DateTimeUTC": "\/Date(1587162517005)\/",
// "Accounts": [
// {
// "AccountID": "54ddab14-4a8d-45cf-86be-076c99a0cea0",
// "Code": "201",
// "Name": "Sales account",
// "Status": "ACTIVE",
// "Type": "REVENUE",
// "TaxType": "OUTPUT",
// "Description": "Income from any normal business trading activity",
// "Class": "REVENUE",
// "EnablePaymentsToAccount": false,
// "ShowInExpenseClaims": false,
// "ReportingCode": "REV",
// "ReportingCodeName": "Revenue",
// "UpdatedDateUTC": "\/Date(1587162517090+0000)\/",
// "AddToWatchlist": false
// }
// ]
// }
//
cId := oJsonResponse:StringOf("Id")
cStatus := oJsonResponse:StringOf("Status")
cProviderName := oJsonResponse:StringOf("ProviderName")
cDateTimeUTC := oJsonResponse:StringOf("DateTimeUTC")
i := 0
nCount_i := oJsonResponse:SizeOfArray("Accounts")
DO WHILE i < nCount_i
oJsonResponse:I := i
cAccountID := oJsonResponse:StringOf("Accounts[i].AccountID")
cCode := oJsonResponse:StringOf("Accounts[i].Code")
cName := oJsonResponse:StringOf("Accounts[i].Name")
cStatus := oJsonResponse:StringOf("Accounts[i].Status")
cType := oJsonResponse:StringOf("Accounts[i].Type")
cTaxType := oJsonResponse:StringOf("Accounts[i].TaxType")
cDescription := oJsonResponse:StringOf("Accounts[i].Description")
cClass := oJsonResponse:StringOf("Accounts[i].Class")
nEnablePaymentsToAccount := oJsonResponse:BoolOf("Accounts[i].EnablePaymentsToAccount")
nShowInExpenseClaims := oJsonResponse:BoolOf("Accounts[i].ShowInExpenseClaims")
cReportingCode := oJsonResponse:StringOf("Accounts[i].ReportingCode")
cReportingCodeName := oJsonResponse:StringOf("Accounts[i].ReportingCodeName")
cUpdatedDateUTC := oJsonResponse:StringOf("Accounts[i].UpdatedDateUTC")
nAddToWatchlist := oJsonResponse:BoolOf("Accounts[i].AddToWatchlist")
i := i + 1
ENDDO
oHttp:destroy()
oJsonToken:destroy()
oJsonRequestBody:destroy()
oResp:destroy()
oJsonResponse:destroy()