Lua
Lua
MYOB: Get List of Company Files
See more MYOB Examples
Gets a list of company files.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()
http.auth_token = "ACCESS_TOKEN"
http.accept = "application/json"
http:set_request_header("x-myobapi-key", "MYOB_API_KEY")
http:set_request_header("x-myobapi-version", "v2")
local strResp = http:quick_get_str("https://ar1.api.myob.com/accountright")
if not http.last_method_success then
print(http.last_error_text)
return
end
print("Response Status Code: " .. http.last_status)
local jsonResponse = chilkat.JsonObject.new()
jsonResponse:load(strResp)
jsonResponse.emit_compact = false
print(jsonResponse:emit())
if http.last_status ~= 200 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": "d2014f64-ffdf-487b-8d12-67a20976aca6",
-- "Name": "Internal Sandbox API",
-- "LibraryPath": "Internal Sandbox API",
-- "ProductVersion": "2013.0",
-- "ProductLevel": {
-- "Code": 20,
-- "Name": "Standard"
-- },
-- "CheckedOutDate": "2013-06-11T01:47:47.0065514",
-- "CheckedOutBy": "developers@myob.com",
-- "Uri": "{cf_uri}",
-- "Country": "AU"
-- }
--
local Id = jsonResponse:string_of("Id")
local Name = jsonResponse:string_of("Name")
local LibraryPath = jsonResponse:string_of("LibraryPath")
local ProductVersion = jsonResponse:string_of("ProductVersion")
local ProductLevelCode = jsonResponse:int_of("ProductLevel.Code")
local ProductLevelName = jsonResponse:string_of("ProductLevel.Name")
local CheckedOutDate = jsonResponse:string_of("CheckedOutDate")
local CheckedOutBy = jsonResponse:string_of("CheckedOutBy")
local Uri = jsonResponse:string_of("Uri")
local Country = jsonResponse:string_of("Country")