Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oSb
LOCAL nStatusCode
LOCAL oJson
LOCAL nId
LOCAL nInvoiceTypeCode
LOCAL cDescription
LOCAL cActiveFrom
LOCAL cActiveTo
LOCAL j
LOCAL nCount_j
LOCAL cName
LOCAL cVersionNumber
LOCAL cStatus
LOCAL i
LOCAL nCount_i
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// Adds the "Authorization: Bearer <access_token>" header.
oHttp: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
oSb := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb("https://preprod-api.myinvois.hasil.gov.my/api/v1.0/documenttypes", oSb)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oSb:destroy()
RETURN
ENDIF
nStatusCode := oHttp:LastStatus
? "response status code = " + Str(nStatusCode)
IF (nStatusCode != 200)
// Failed.
? oSb:GetAsString()
oHttp:destroy()
oSb:destroy()
RETURN
ENDIF
// 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
oJson := CreateObject("Chilkat.JsonObject")
oJson:LoadSb(oSb)
i := 0
nCount_i := oJson:SizeOfArray("result")
DO WHILE i < nCount_i
oJson:I := i
nId := oJson:IntOf("result[i].id")
nInvoiceTypeCode := oJson:IntOf("result[i].invoiceTypeCode")
cDescription := oJson:StringOf("result[i].description")
cActiveFrom := oJson:StringOf("result[i].activeFrom")
cActiveTo := oJson:StringOf("result[i].activeTo")
j := 0
nCount_j := oJson:SizeOfArray("result[i].documentTypeVersions")
DO WHILE j < nCount_j
oJson:J := j
nId := oJson:IntOf("result[i].documentTypeVersions[j].id")
cName := oJson:StringOf("result[i].documentTypeVersions[j].name")
cDescription := oJson:StringOf("result[i].documentTypeVersions[j].description")
cActiveFrom := oJson:StringOf("result[i].documentTypeVersions[j].activeFrom")
cActiveTo := oJson:StringOf("result[i].documentTypeVersions[j].activeTo")
cVersionNumber := oJson:StringOf("result[i].documentTypeVersions[j].versionNumber")
cStatus := oJson:StringOf("result[i].documentTypeVersions[j].status")
j := j + 1
ENDDO
i := i + 1
ENDDO
oHttp:destroy()
oSb:destroy()
oJson:destroy()