Retrieve VAT obligations
curl -X GET https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/obligations?from=2018-06-25&to=2019-01-01 \
-H 'Authorization: Bearer HMRC_ACCESS_TOKEN' \
-H 'Accept: application/vnd.hmrc.1.0+json'
Use ChilkatAx-9.5.0-win32.pkg
Procedure Test
Handle hoRest
Boolean iSuccess
Boolean iBTls
Integer iPort
Boolean iBAutoReconnect
Variant vSbResponseBody
Handle hoSbResponseBody
Integer iRespStatusCode
Handle hoJsonResponse
Integer i
Integer iCount_i
String sStart
String sEnd
String sDue
String sStatus
String sPeriodKey
String sReceived
String sTemp1
Integer iTemp1
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
// URL: https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/obligations?from=2018-06-25&to=2019-01-01
Move True To iBTls
Move 443 To iPort
Move True To iBAutoReconnect
Get ComConnect Of hoRest "test-api.service.hmrc.gov.uk" iPort iBTls iBAutoReconnect To iSuccess
If (iSuccess <> True) Begin
Get ComConnectFailReason Of hoRest To iTemp1
Showln "ConnectFailReason: " iTemp1
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComAddHeader Of hoRest "Authorization" "Bearer HMRC_ACCESS_TOKEN" To iSuccess
Get ComAddHeader Of hoRest "Accept" "application/vnd.hmrc.1.0+json" To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComFullRequestNoBodySb Of hoRest "GET" "/organisations/vat/MY_HMRC_VRN/obligations?from=2018-06-25&to=2019-01-01" vSbResponseBody To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Status Code = " iRespStatusCode
Showln "Response Header:"
Get ComResponseHeader Of hoRest To sTemp1
Showln sTemp1
Showln "Response Body:"
Get ComGetAsString Of hoSbResponseBody To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResponse
If (Not(IsComObjectCreated(hoJsonResponse))) Begin
Send CreateComObject of hoJsonResponse
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJsonResponse vSbResponseBody To iSuccess
// See the Online Tool for Generating JSON Parse Code
Move 0 To i
Get ComSizeOfArray Of hoJsonResponse "obligations" To iCount_i
While (i < iCount_i)
Set ComI Of hoJsonResponse To i
Get ComStringOf Of hoJsonResponse "obligations[i].start" To sStart
Get ComStringOf Of hoJsonResponse "obligations[i].end" To sEnd
Get ComStringOf Of hoJsonResponse "obligations[i].due" To sDue
Get ComStringOf Of hoJsonResponse "obligations[i].status" To sStatus
Get ComStringOf Of hoJsonResponse "obligations[i].periodKey" To sPeriodKey
Get ComStringOf Of hoJsonResponse "obligations[i].received" To sReceived
Move i + 1 To i
Loop
End_Procedure
{
"obligations": [
{
"start": "2017-01-01",
"end": "2017-03-31",
"due": "2017-05-07",
"status": "F",
"periodKey": "18A1",
"received": "2017-05-06"
},
{
"start": "2017-04-01",
"end": "2017-06-30",
"due": "2017-08-07",
"status": "O",
"periodKey": "18A2"
}
]
}