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_CkRestW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
HCkRestW rest;
BOOL success;
BOOL bTls;
int port;
BOOL bAutoReconnect;
HCkStringBuilderW sbResponseBody;
int respStatusCode;
HCkJsonObjectW jsonResponse;
int i;
int count_i;
const wchar_t *taxPeriodFrom;
const wchar_t *taxPeriodTo;
const wchar_t *type;
const wchar_t *originalAmount;
const wchar_t *outstandingAmount;
const wchar_t *due;
rest = CkRestW_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 = CkRestW_Connect(rest,L"test-api.service.hmrc.gov.uk",port,bTls,bAutoReconnect);
if (success != TRUE) {
wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
return;
}
CkRestW_AddHeader(rest,L"Authorization",L"Bearer HMRC_ACCESS_TOKEN");
CkRestW_AddHeader(rest,L"Accept",L"application/vnd.hmrc.1.0+json");
sbResponseBody = CkStringBuilderW_Create();
success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/organisations/vat/MY_HMRC_VRN/liabilities?from=2018-06-25&to=2019-02-17",sbResponseBody);
if (success != TRUE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
respStatusCode = CkRestW_getResponseStatusCode(rest);
if (respStatusCode >= 400) {
wprintf(L"Response Status Code = %d\n",respStatusCode);
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkRestW_responseHeader(rest));
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody));
CkRestW_Dispose(rest);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
jsonResponse = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(jsonResponse,sbResponseBody);
// See the Online Tool for Generating JSON Parse Code
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"liabilities");
while (i < count_i) {
CkJsonObjectW_putI(jsonResponse,i);
taxPeriodFrom = CkJsonObjectW_stringOf(jsonResponse,L"liabilities[i].taxPeriod.from");
taxPeriodTo = CkJsonObjectW_stringOf(jsonResponse,L"liabilities[i].taxPeriod.to");
type = CkJsonObjectW_stringOf(jsonResponse,L"liabilities[i].type");
originalAmount = CkJsonObjectW_stringOf(jsonResponse,L"liabilities[i].originalAmount");
outstandingAmount = CkJsonObjectW_stringOf(jsonResponse,L"liabilities[i].outstandingAmount");
due = CkJsonObjectW_stringOf(jsonResponse,L"liabilities[i].due");
i = i + 1;
}
CkRestW_Dispose(rest);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jsonResponse);
}
{
"liabilities": [
{
"taxPeriod": {
"from": "2018-04-06",
"to": "2018-07-06"
},
"type": "VAT ...",
"originalAmount": 6000.3,
"outstandingAmount": 100.51,
"due": "2018-07-06"
}
]
}