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'
#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 *start;
const wchar_t *end;
const wchar_t *due;
const wchar_t *status;
const wchar_t *periodKey;
const wchar_t *received;
rest = CkRestW_Create();
// URL: https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/obligations?from=2018-06-25&to=2019-01-01
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/obligations?from=2018-06-25&to=2019-01-01",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"obligations");
while (i < count_i) {
CkJsonObjectW_putI(jsonResponse,i);
start = CkJsonObjectW_stringOf(jsonResponse,L"obligations[i].start");
end = CkJsonObjectW_stringOf(jsonResponse,L"obligations[i].end");
due = CkJsonObjectW_stringOf(jsonResponse,L"obligations[i].due");
status = CkJsonObjectW_stringOf(jsonResponse,L"obligations[i].status");
periodKey = CkJsonObjectW_stringOf(jsonResponse,L"obligations[i].periodKey");
received = CkJsonObjectW_stringOf(jsonResponse,L"obligations[i].received");
i = i + 1;
}
CkRestW_Dispose(rest);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(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"
}
]
}