Retrieve VAT liabilities
curl -X GET https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/liabilities?from=2018-06-25&to=2019-02-17 \
-H 'Authorization: Bearer HMRC_ACCESS_TOKEN' \
-H 'Accept: application/vnd.hmrc.1.0+json'
LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJsonResponse
LOCAL i
LOCAL lnCount_i
LOCAL lcTaxPeriodFrom
LOCAL lcTaxPeriodTo
LOCAL lcType
LOCAL lcOriginalAmount
LOCAL lcOutstandingAmount
LOCAL lcDue
loRest = CreateObject('Chilkat_9_5_0.Rest')
* URL: https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/liabilities?from=2018-06-25&to=2019-02-17
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("test-api.service.hmrc.gov.uk",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
? loRest.LastErrorText
RELEASE loRest
CANCEL
ENDIF
loRest.AddHeader("Authorization","Bearer HMRC_ACCESS_TOKEN")
loRest.AddHeader("Accept","application/vnd.hmrc.1.0+json")
loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/organisations/vat/MY_HMRC_VRN/liabilities?from=2018-06-25&to=2019-02-17",loSbResponseBody)
IF (lnSuccess <> 1) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loSbResponseBody
CANCEL
ENDIF
lnRespStatusCode = loRest.ResponseStatusCode
IF (lnRespStatusCode >= 400) THEN
? "Response Status Code = " + STR(lnRespStatusCode)
? "Response Header:"
? loRest.ResponseHeader
? "Response Body:"
? loSbResponseBody.GetAsString()
RELEASE loRest
RELEASE loSbResponseBody
CANCEL
ENDIF
loJsonResponse = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonResponse.LoadSb(loSbResponseBody)
* See the Online Tool for Generating JSON Parse Code
i = 0
lnCount_i = loJsonResponse.SizeOfArray("liabilities")
DO WHILE i < lnCount_i
loJsonResponse.I = i
lcTaxPeriodFrom = loJsonResponse.StringOf("liabilities[i].taxPeriod.from")
lcTaxPeriodTo = loJsonResponse.StringOf("liabilities[i].taxPeriod.to")
lcType = loJsonResponse.StringOf("liabilities[i].type")
lcOriginalAmount = loJsonResponse.StringOf("liabilities[i].originalAmount")
lcOutstandingAmount = loJsonResponse.StringOf("liabilities[i].outstandingAmount")
lcDue = loJsonResponse.StringOf("liabilities[i].due")
i = i + 1
ENDDO
RELEASE loRest
RELEASE loSbResponseBody
RELEASE loJsonResponse
{
"liabilities": [
{
"taxPeriod": {
"from": "2018-04-06",
"to": "2018-07-06"
},
"type": "VAT ...",
"originalAmount": 6000.3,
"outstandingAmount": 100.51,
"due": "2018-07-06"
}
]
}