AutoIt
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oHttp = ObjCreate("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 = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oHttp.QuickGetSb("https://preprod-api.myinvois.hasil.gov.my/api/v1.0/documenttypes",$oSb)
If ($bSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
Local $iStatusCode = $oHttp.LastStatus
ConsoleWrite("response status code = " & $iStatusCode & @CRLF)
If ($iStatusCode <> 200) Then
; Failed.
ConsoleWrite($oSb.GetAsString() & @CRLF)
Exit
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 = ObjCreate("Chilkat.JsonObject")
$oJson.LoadSb($oSb)
Local $id
Local $invoiceTypeCode
Local $sDescription
Local $sActiveFrom
Local $sActiveTo
Local $iJ
Local $iCount_j
Local $sName
Local $sVersionNumber
Local $status
Local $i = 0
Local $iCount_i = $oJson.SizeOfArray("result")
While $i < $iCount_i
$oJson.I = $i
$id = $oJson.IntOf("result[i].id")
$invoiceTypeCode = $oJson.IntOf("result[i].invoiceTypeCode")
$sDescription = $oJson.StringOf("result[i].description")
$sActiveFrom = $oJson.StringOf("result[i].activeFrom")
$sActiveTo = $oJson.StringOf("result[i].activeTo")
$iJ = 0
$iCount_j = $oJson.SizeOfArray("result[i].documentTypeVersions")
While $iJ < $iCount_j
$oJson.J = $iJ
$id = $oJson.IntOf("result[i].documentTypeVersions[j].id")
$sName = $oJson.StringOf("result[i].documentTypeVersions[j].name")
$sDescription = $oJson.StringOf("result[i].documentTypeVersions[j].description")
$sActiveFrom = $oJson.StringOf("result[i].documentTypeVersions[j].activeFrom")
$sActiveTo = $oJson.StringOf("result[i].documentTypeVersions[j].activeTo")
$sVersionNumber = $oJson.StringOf("result[i].documentTypeVersions[j].versionNumber")
$status = $oJson.StringOf("result[i].documentTypeVersions[j].status")
$iJ = $iJ + 1
Wend
$i = $i + 1
Wend