Lua Requires Chilkat v11.0.0+
Lua
Xero Update Account Details
See more Xero Examples
Update some details of an account in a Xero company (Accounting API)Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
local jsonToken = chilkat.JsonObject.new()
local success = jsonToken:load_file("qa_data/tokens/xero-access-token.json")
if not success then
print(jsonToken.last_error_text)
return
end
http.auth_token = jsonToken:string_of("access_token")
-- Replace the value here with an actual tenant ID obtained from this example:
-- Get Xero Tenant IDs
http:set_request_header("Xero-tenant-id", "83299b9e-5747-4a14-a18a-a6c94f824eb7")
http.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
local jsonRequestBody = chilkat.JsonObject.new()
jsonRequestBody:update_string("AccountID", "54ddab14-4a8d-45cf-86be-076c99a0cea0")
jsonRequestBody:update_string("Name", "Sales account")
jsonRequestBody:update_string("Type", "REVENUE")
jsonRequestBody:update_string("TaxType", "OUTPUT")
jsonRequestBody:update_string("Description", "Income from any normal business trading activity")
jsonRequestBody:update_string("EnablePaymentsToAccount", "false")
jsonRequestBody:update_string("ShowInExpenseClaims", "false")
local url = "https://api.xero.com/api.xro/2.0/Accounts/54ddab14-4a8d-45cf-86be-076c99a0cea0"
local resp = chilkat.HttpResponse.new()
success = http:http_json("POST", url, jsonRequestBody, "application/json", resp)
if not success then
print(http.last_error_text)
return
end
print("Response Status Code: " .. resp.status_code)
local jsonResponse = chilkat.JsonObject.new()
jsonResponse:load(resp.body_str)
jsonResponse.emit_compact = false
print(jsonResponse:emit())
if resp.status_code >= 300 then
print("Failed.")
return
end
-- 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
-- }
-- ]
-- }
--
local AccountID = ""
local Code = ""
local Name = ""
local Type = ""
local TaxType = ""
local Description = ""
local Class = ""
local EnablePaymentsToAccount = false
local ShowInExpenseClaims = false
local ReportingCode = ""
local ReportingCodeName = ""
local UpdatedDateUTC = ""
local AddToWatchlist = false
local Id = jsonResponse:string_of("Id")
local Status = jsonResponse:string_of("Status")
local ProviderName = jsonResponse:string_of("ProviderName")
local DateTimeUTC = jsonResponse:string_of("DateTimeUTC")
local i = 0
local count_i = jsonResponse:size_of_array("Accounts")
while i < count_i do
jsonResponse.i = i
AccountID = jsonResponse:string_of("Accounts[i].AccountID")
Code = jsonResponse:string_of("Accounts[i].Code")
Name = jsonResponse:string_of("Accounts[i].Name")
Status = jsonResponse:string_of("Accounts[i].Status")
Type = jsonResponse:string_of("Accounts[i].Type")
TaxType = jsonResponse:string_of("Accounts[i].TaxType")
Description = jsonResponse:string_of("Accounts[i].Description")
Class = jsonResponse:string_of("Accounts[i].Class")
EnablePaymentsToAccount = jsonResponse:bool_of("Accounts[i].EnablePaymentsToAccount")
ShowInExpenseClaims = jsonResponse:bool_of("Accounts[i].ShowInExpenseClaims")
ReportingCode = jsonResponse:string_of("Accounts[i].ReportingCode")
ReportingCodeName = jsonResponse:string_of("Accounts[i].ReportingCodeName")
UpdatedDateUTC = jsonResponse:string_of("Accounts[i].UpdatedDateUTC")
AddToWatchlist = jsonResponse:bool_of("Accounts[i].AddToWatchlist")
i = i + 1
end