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'
load ./chilkat.dll
set rest [new_CkRest]
# URL: https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/obligations?from=2018-06-25&to=2019-01-01
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/obligations?from=2018-06-25&to=2019-01-01" $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 "obligations"]
while {[expr $i < $count_i]} {
CkJsonObject_put_I $jsonResponse $i
set start [CkJsonObject_stringOf $jsonResponse "obligations[i].start"]
set end [CkJsonObject_stringOf $jsonResponse "obligations[i].end"]
set due [CkJsonObject_stringOf $jsonResponse "obligations[i].due"]
set status [CkJsonObject_stringOf $jsonResponse "obligations[i].status"]
set periodKey [CkJsonObject_stringOf $jsonResponse "obligations[i].periodKey"]
set received [CkJsonObject_stringOf $jsonResponse "obligations[i].received"]
set i [expr $i + 1]
}
delete_CkRest $rest
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jsonResponse
{
"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"
}
]
}