Xbase++
Xbase++
MYOB: Get List of Company Files
See more MYOB Examples
Gets a list of company files.Chilkat Xbase++ Downloads
LOCAL oHttp
LOCAL cStrResp
LOCAL oJsonResponse
LOCAL cId
LOCAL cName
LOCAL cLibraryPath
LOCAL cProductVersion
LOCAL nProductLevelCode
LOCAL cProductLevelName
LOCAL cCheckedOutDate
LOCAL cCheckedOutBy
LOCAL cUri
LOCAL cCountry
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
oHttp:AuthToken := "ACCESS_TOKEN"
oHttp:Accept := "application/json"
oHttp:SetRequestHeader("x-myobapi-key", "MYOB_API_KEY")
oHttp:SetRequestHeader("x-myobapi-version", "v2")
cStrResp := oHttp:QuickGetStr("https://ar1.api.myob.com/accountright")
IF (oHttp:LastMethodSuccess != 1)
? oHttp:LastErrorText
oHttp:destroy()
RETURN
ENDIF
? "Response Status Code: " + Str(oHttp:LastStatus)
oJsonResponse := CreateObject("Chilkat.JsonObject")
oJsonResponse:Load(cStrResp)
oJsonResponse:EmitCompact := 0
? oJsonResponse:Emit()
IF (oHttp:LastStatus != 200)
? "Failed."
oHttp: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": "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"
// }
//
cId := oJsonResponse:StringOf("Id")
cName := oJsonResponse:StringOf("Name")
cLibraryPath := oJsonResponse:StringOf("LibraryPath")
cProductVersion := oJsonResponse:StringOf("ProductVersion")
nProductLevelCode := oJsonResponse:IntOf("ProductLevel.Code")
cProductLevelName := oJsonResponse:StringOf("ProductLevel.Name")
cCheckedOutDate := oJsonResponse:StringOf("CheckedOutDate")
cCheckedOutBy := oJsonResponse:StringOf("CheckedOutBy")
cUri := oJsonResponse:StringOf("Uri")
cCountry := oJsonResponse:StringOf("Country")
oHttp:destroy()
oJsonResponse:destroy()