Unicode C HMRC VAT MTD: Submit VAT return for period

Back to Index

Submit VAT return for period

Documentation: https://developer.service.hmrc.gov.uk/api-documentation/docs/api/service/vat-api/1.0#_submit-vat-return-for-period_post_accordion

CURL Command

curl -X POST  https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/returns \
-H 'Authorization: Bearer HMRC_ACCESS_TOKEN' \
-H 'Accept: application/vnd.hmrc.1.0+json' \
-H 'Content-Type: application/json' \
-d '{
  "periodKey": "A001",
  "vatDueSales": 105.50,
  "vatDueAcquisitions": -100.45,
  "totalVatDue": 5.05,
  "vatReclaimedCurrPeriod": 105.15,
  "netVatDue": 100.10,
  "totalValueSalesExVAT": 300,
  "totalValuePurchasesExVAT": 300,
  "totalValueGoodsSuppliedExVAT": 3000,
  "totalAcquisitionsExVAT": 3000,
  "finalised": true
}'

Unicode C Example

#include <C_CkRestW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkStringBuilderW sbResponseBody;
    int respStatusCode;
    HCkJsonObjectW jsonResponse;
    const wchar_t *processingDate;
    const wchar_t *paymentIndicator;
    const wchar_t *formBundleNumber;

    rest = CkRestW_Create();

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

    //  See the Online Tool for Generating JSON Creation Code
    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"periodKey",L"A001");
    CkJsonObjectW_UpdateNumber(json,L"vatDueSales",L"105.50");
    CkJsonObjectW_UpdateNumber(json,L"vatDueAcquisitions",L"-100.45");
    CkJsonObjectW_UpdateNumber(json,L"totalVatDue",L"5.05");
    CkJsonObjectW_UpdateNumber(json,L"vatReclaimedCurrPeriod",L"105.15");
    CkJsonObjectW_UpdateNumber(json,L"netVatDue",L"100.10");
    CkJsonObjectW_UpdateNumber(json,L"totalValueSalesExVAT",L"300");
    CkJsonObjectW_UpdateNumber(json,L"totalValuePurchasesExVAT",L"300");
    CkJsonObjectW_UpdateNumber(json,L"totalValueGoodsSuppliedExVAT",L"3000");
    CkJsonObjectW_UpdateNumber(json,L"totalAcquisitionsExVAT",L"3000");
    CkJsonObjectW_UpdateBool(json,L"finalised",TRUE);

    CkRestW_AddHeader(rest,L"Content-Type",L"application/json");
    CkRestW_AddHeader(rest,L"Authorization",L"Bearer HMRC_ACCESS_TOKEN");
    CkRestW_AddHeader(rest,L"Accept",L"application/vnd.hmrc.1.0+json");

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);
    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestSb(rest,L"POST",L"/organisations/vat/MY_HMRC_VRN/returns",sbRequestBody,sbResponseBody);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        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);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jsonResponse = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jsonResponse,sbResponseBody);

    //  See the Online Tool for Generating JSON Parse Code

    processingDate = CkJsonObjectW_stringOf(jsonResponse,L"processingDate");
    paymentIndicator = CkJsonObjectW_stringOf(jsonResponse,L"paymentIndicator");
    formBundleNumber = CkJsonObjectW_stringOf(jsonResponse,L"formBundleNumber");


    CkRestW_Dispose(rest);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbRequestBody);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jsonResponse);

    }

Sample JSON Response Body

{
  "processingDate": "2019-02-18T14:37:56.561Z",
  "paymentIndicator": "BANK",
  "formBundleNumber": "948551092841"
}