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'
#include <C_CkRest.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
HCkRest rest;
BOOL success;
BOOL bTls;
int port;
BOOL bAutoReconnect;
HCkStringBuilder sbResponseBody;
int respStatusCode;
HCkJsonObject jsonResponse;
int i;
int count_i;
const char *taxPeriodFrom;
const char *taxPeriodTo;
const char *type;
const char *originalAmount;
const char *outstandingAmount;
const char *due;
rest = CkRest_Create();
// URL: https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/liabilities?from=2018-06-25&to=2019-02-17
bTls = TRUE;
port = 443;
bAutoReconnect = TRUE;
success = CkRest_Connect(rest,"test-api.service.hmrc.gov.uk",port,bTls,bAutoReconnect);
if (success != TRUE) {
printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
return;
}
CkRest_AddHeader(rest,"Authorization","Bearer HMRC_ACCESS_TOKEN");
CkRest_AddHeader(rest,"Accept","application/vnd.hmrc.1.0+json");
sbResponseBody = CkStringBuilder_Create();
success = CkRest_FullRequestNoBodySb(rest,"GET","/organisations/vat/MY_HMRC_VRN/liabilities?from=2018-06-25&to=2019-02-17",sbResponseBody);
if (success != TRUE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
respStatusCode = CkRest_getResponseStatusCode(rest);
if (respStatusCode >= 400) {
printf("Response Status Code = %d\n",respStatusCode);
printf("Response Header:\n");
printf("%s\n",CkRest_responseHeader(rest));
printf("Response Body:\n");
printf("%s\n",CkStringBuilder_getAsString(sbResponseBody));
CkRest_Dispose(rest);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
jsonResponse = CkJsonObject_Create();
CkJsonObject_LoadSb(jsonResponse,sbResponseBody);
// See the Online Tool for Generating JSON Parse Code
i = 0;
count_i = CkJsonObject_SizeOfArray(jsonResponse,"liabilities");
while (i < count_i) {
CkJsonObject_putI(jsonResponse,i);
taxPeriodFrom = CkJsonObject_stringOf(jsonResponse,"liabilities[i].taxPeriod.from");
taxPeriodTo = CkJsonObject_stringOf(jsonResponse,"liabilities[i].taxPeriod.to");
type = CkJsonObject_stringOf(jsonResponse,"liabilities[i].type");
originalAmount = CkJsonObject_stringOf(jsonResponse,"liabilities[i].originalAmount");
outstandingAmount = CkJsonObject_stringOf(jsonResponse,"liabilities[i].outstandingAmount");
due = CkJsonObject_stringOf(jsonResponse,"liabilities[i].due");
i = i + 1;
}
CkRest_Dispose(rest);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jsonResponse);
}
{
"liabilities": [
{
"taxPeriod": {
"from": "2018-04-06",
"to": "2018-07-06"
},
"type": "VAT ...",
"originalAmount": 6000.3,
"outstandingAmount": 100.51,
"due": "2018-07-06"
}
]
}