C HMRC VAT MTD: View VAT Return

Back to Index

Retrieve a previously submitted VAT return. This example retrieves the VAT return with period key "A001".

Documentation: https://developer.service.hmrc.gov.uk/api-documentation/docs/api/service/vat-api/1.0#_view-vat-return_get_accordion

CURL Command

curl -X GET  https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/returns/A001 \
-H 'Authorization: Bearer HMRC_ACCESS_TOKEN' \
-H 'Accept: application/vnd.hmrc.1.0+json'

C Example

#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;
    const char *periodKey;
    const char *vatDueSales;
    const char *vatDueAcquisitions;
    const char *totalVatDue;
    const char *vatReclaimedCurrPeriod;
    const char *netVatDue;
    int totalValueSalesExVAT;
    int totalValuePurchasesExVAT;
    int totalValueGoodsSuppliedExVAT;
    int totalAcquisitionsExVAT;

    rest = CkRest_Create();

    //  URL: https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/returns/A001
    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/returns/A001",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

    periodKey = CkJsonObject_stringOf(jsonResponse,"periodKey");
    vatDueSales = CkJsonObject_stringOf(jsonResponse,"vatDueSales");
    vatDueAcquisitions = CkJsonObject_stringOf(jsonResponse,"vatDueAcquisitions");
    totalVatDue = CkJsonObject_stringOf(jsonResponse,"totalVatDue");
    vatReclaimedCurrPeriod = CkJsonObject_stringOf(jsonResponse,"vatReclaimedCurrPeriod");
    netVatDue = CkJsonObject_stringOf(jsonResponse,"netVatDue");
    totalValueSalesExVAT = CkJsonObject_IntOf(jsonResponse,"totalValueSalesExVAT");
    totalValuePurchasesExVAT = CkJsonObject_IntOf(jsonResponse,"totalValuePurchasesExVAT");
    totalValueGoodsSuppliedExVAT = CkJsonObject_IntOf(jsonResponse,"totalValueGoodsSuppliedExVAT");
    totalAcquisitionsExVAT = CkJsonObject_IntOf(jsonResponse,"totalAcquisitionsExVAT");


    CkRest_Dispose(rest);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jsonResponse);

    }

Sample JSON Response Body

{
  "periodKey": "A001",
  "vatDueSales": 105.5,
  "vatDueAcquisitions": -100.45,
  "totalVatDue": 5.05,
  "vatReclaimedCurrPeriod": 105.15,
  "netVatDue": 100.1,
  "totalValueSalesExVAT": 300,
  "totalValuePurchasesExVAT": 300,
  "totalValueGoodsSuppliedExVAT": 3000,
  "totalAcquisitionsExVAT": 3000
}