PowerBuilder
PowerBuilder
MyInvois Malaysia Get Document Types
See more Malaysia MyInvois Examples
There are multiple types of documents supported by MyInvois, and this API retrieves their definitions through API call.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Sb
integer li_StatusCode
oleobject loo_Json
integer li_Id
integer li_InvoiceTypeCode
string ls_Description
string ls_ActiveFrom
string ls_ActiveTo
integer j
integer li_Count_j
string ls_Name
string ls_VersionNumber
string ls_Status
integer i
integer li_Count_i
li_Success = 0
// This example assumes 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
// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"
// Note: The access token is valid for a short amount of time. Perhaps 1 hour.
// The access token is used in the "Authorization: Bearer <access_token>" header in subsequent requests until it expires.
// Your application would then need to get a new access token, and so on..
// To get an access token, see How to Get a MyInvois Access Token
loo_Sb = create oleobject
li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_Http.QuickGetSb("https://preprod-api.myinvois.hasil.gov.my/api/v1.0/documenttypes",loo_Sb)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Sb
return
end if
li_StatusCode = loo_Http.LastStatus
Write-Debug "response status code = " + string(li_StatusCode)
if li_StatusCode <> 200 then
// Failed.
Write-Debug loo_Sb.GetAsString()
destroy loo_Http
destroy loo_Sb
return
end if
// Sample response:
// {"result":
// [
// {"id":45,
// "invoiceTypeCode":4,
// "description":"Invoice",
// "activeFrom":"2015-02-13T13:15:00Z",
// "activeTo":"2027-03-01T00:00:00Z",
// "documentTypeVersions":
// [
// {"id":454,
// "name":"1.0",
// "description":"Invoice version 1.1",
// "activeFrom":"2015-02-13T13:15:00Z",
// "activeTo":"2027-03-01T00:00:00Z",
// "versionNumber":1.1,
// "status":"published"
// }
// ]
// }
// ]
// }
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.LoadSb(loo_Sb)
i = 0
li_Count_i = loo_Json.SizeOfArray("result")
do while i < li_Count_i
loo_Json.I = i
li_Id = loo_Json.IntOf("result[i].id")
li_InvoiceTypeCode = loo_Json.IntOf("result[i].invoiceTypeCode")
ls_Description = loo_Json.StringOf("result[i].description")
ls_ActiveFrom = loo_Json.StringOf("result[i].activeFrom")
ls_ActiveTo = loo_Json.StringOf("result[i].activeTo")
j = 0
li_Count_j = loo_Json.SizeOfArray("result[i].documentTypeVersions")
do while j < li_Count_j
loo_Json.J = j
li_Id = loo_Json.IntOf("result[i].documentTypeVersions[j].id")
ls_Name = loo_Json.StringOf("result[i].documentTypeVersions[j].name")
ls_Description = loo_Json.StringOf("result[i].documentTypeVersions[j].description")
ls_ActiveFrom = loo_Json.StringOf("result[i].documentTypeVersions[j].activeFrom")
ls_ActiveTo = loo_Json.StringOf("result[i].documentTypeVersions[j].activeTo")
ls_VersionNumber = loo_Json.StringOf("result[i].documentTypeVersions[j].versionNumber")
ls_Status = loo_Json.StringOf("result[i].documentTypeVersions[j].status")
j = j + 1
loop
i = i + 1
loop
destroy loo_Http
destroy loo_Sb
destroy loo_Json