Retrieve VAT payments
curl -X GET https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/payments?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/payments?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/payments?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 "payments"]
while {[expr $i < $count_i]} {
CkJsonObject_put_I $jsonResponse $i
set amount [CkJsonObject_stringOf $jsonResponse "payments[i].amount"]
set received [CkJsonObject_stringOf $jsonResponse "payments[i].received"]
set i [expr $i + 1]
}
delete_CkRest $rest
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jsonResponse
{
"payments": [
{
"amount": 100.05,
"received": "2018-04-06"
}
]
}