Sample code for 30+ languages & platforms
PowerBuilder

MYOB: Get List of Company Files

See more MYOB Examples

Gets a list of company files.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
oleobject loo_Http
string ls_StrResp
oleobject loo_JsonResponse
string ls_Id
string ls_Name
string ls_LibraryPath
string ls_ProductVersion
integer li_ProductLevelCode
string ls_ProductLevelName
string ls_CheckedOutDate
string ls_CheckedOutBy
string ls_Uri
string ls_Country

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Http.AuthToken = "ACCESS_TOKEN"

loo_Http.Accept = "application/json"

loo_Http.SetRequestHeader("x-myobapi-key","MYOB_API_KEY")
loo_Http.SetRequestHeader("x-myobapi-version","v2")

ls_StrResp = loo_Http.QuickGetStr("https://ar1.api.myob.com/accountright")
if loo_Http.LastMethodSuccess <> 1 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    return
end if

Write-Debug "Response Status Code: " + string(loo_Http.LastStatus)

loo_JsonResponse = create oleobject
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat.JsonObject")

loo_JsonResponse.Load(ls_StrResp)
loo_JsonResponse.EmitCompact = 0
Write-Debug loo_JsonResponse.Emit()

if loo_Http.LastStatus <> 200 then
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_JsonResponse
    return
end if

// 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"
// }
// 

ls_Id = loo_JsonResponse.StringOf("Id")
ls_Name = loo_JsonResponse.StringOf("Name")
ls_LibraryPath = loo_JsonResponse.StringOf("LibraryPath")
ls_ProductVersion = loo_JsonResponse.StringOf("ProductVersion")
li_ProductLevelCode = loo_JsonResponse.IntOf("ProductLevel.Code")
ls_ProductLevelName = loo_JsonResponse.StringOf("ProductLevel.Name")
ls_CheckedOutDate = loo_JsonResponse.StringOf("CheckedOutDate")
ls_CheckedOutBy = loo_JsonResponse.StringOf("CheckedOutBy")
ls_Uri = loo_JsonResponse.StringOf("Uri")
ls_Country = loo_JsonResponse.StringOf("Country")


destroy loo_Http
destroy loo_JsonResponse