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'
load ./chilkat.dll
set rest [new_CkRest]
# URL: https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/liabilities?from=2018-06-25&to=2019-02-17
set bTls 1
set port 443
set bAutoReconnect 1
set success [CkRest_Connect $rest "test-api.service.hmrc.gov.uk" $port $bTls $bAutoReconnect]
if {[expr $success != 1]} then {
puts "ConnectFailReason: [CkRest_get_ConnectFailReason $rest]"
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
exit
}
CkRest_AddHeader $rest "Authorization" "Bearer HMRC_ACCESS_TOKEN"
CkRest_AddHeader $rest "Accept" "application/vnd.hmrc.1.0+json"
set sbResponseBody [new_CkStringBuilder]
set success [CkRest_FullRequestNoBodySb $rest "GET" "/organisations/vat/MY_HMRC_VRN/liabilities?from=2018-06-25&to=2019-02-17" $sbResponseBody]
if {[expr $success != 1]} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
delete_CkStringBuilder $sbResponseBody
exit
}
set respStatusCode [CkRest_get_ResponseStatusCode $rest]
if {[expr $respStatusCode >= 400]} then {
puts "Response Status Code = $respStatusCode"
puts "Response Header:"
puts [CkRest_responseHeader $rest]
puts "Response Body:"
puts [CkStringBuilder_getAsString $sbResponseBody]
delete_CkRest $rest
delete_CkStringBuilder $sbResponseBody
exit
}
set jsonResponse [new_CkJsonObject]
CkJsonObject_LoadSb $jsonResponse $sbResponseBody
# See the Online Tool for Generating JSON Parse Code
set i 0
set count_i [CkJsonObject_SizeOfArray $jsonResponse "liabilities"]
while {[expr $i < $count_i]} {
CkJsonObject_put_I $jsonResponse $i
set taxPeriodFrom [CkJsonObject_stringOf $jsonResponse "liabilities[i].taxPeriod.from"]
set taxPeriodTo [CkJsonObject_stringOf $jsonResponse "liabilities[i].taxPeriod.to"]
set type [CkJsonObject_stringOf $jsonResponse "liabilities[i].type"]
set originalAmount [CkJsonObject_stringOf $jsonResponse "liabilities[i].originalAmount"]
set outstandingAmount [CkJsonObject_stringOf $jsonResponse "liabilities[i].outstandingAmount"]
set due [CkJsonObject_stringOf $jsonResponse "liabilities[i].due"]
set i [expr $i + 1]
}
delete_CkRest $rest
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jsonResponse
{
"liabilities": [
{
"taxPeriod": {
"from": "2018-04-06",
"to": "2018-07-06"
},
"type": "VAT ...",
"originalAmount": 6000.3,
"outstandingAmount": 100.51,
"due": "2018-07-06"
}
]
}