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 <CkRestW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    CkRestW rest;
    bool success;

    //  URL: https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/returns
    bool bTls = true;
    int port = 443;
    bool bAutoReconnect = true;
    success = rest.Connect(L"test-api.service.hmrc.gov.uk",port,bTls,bAutoReconnect);
    if (success != true) {
        wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    //  See the Online Tool for Generating JSON Creation Code
    CkJsonObjectW json;
    json.UpdateString(L"periodKey",L"A001");
    json.UpdateNumber(L"vatDueSales",L"105.50");
    json.UpdateNumber(L"vatDueAcquisitions",L"-100.45");
    json.UpdateNumber(L"totalVatDue",L"5.05");
    json.UpdateNumber(L"vatReclaimedCurrPeriod",L"105.15");
    json.UpdateNumber(L"netVatDue",L"100.10");
    json.UpdateNumber(L"totalValueSalesExVAT",L"300");
    json.UpdateNumber(L"totalValuePurchasesExVAT",L"300");
    json.UpdateNumber(L"totalValueGoodsSuppliedExVAT",L"3000");
    json.UpdateNumber(L"totalAcquisitionsExVAT",L"3000");
    json.UpdateBool(L"finalised",true);

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

    CkStringBuilderW sbRequestBody;
    json.EmitSb(sbRequestBody);
    CkStringBuilderW sbResponseBody;
    success = rest.FullRequestSb(L"POST",L"/organisations/vat/MY_HMRC_VRN/returns",sbRequestBody,sbResponseBody);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    int respStatusCode = rest.get_ResponseStatusCode();
    if (respStatusCode >= 400) {
        wprintf(L"Response Status Code = %d\n",respStatusCode);
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",rest.responseHeader());
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",sbResponseBody.getAsString());
        return;
    }

    CkJsonObjectW jsonResponse;
    jsonResponse.LoadSb(sbResponseBody);

    //  See the Online Tool for Generating JSON Parse Code
    const wchar_t *processingDate = 0;
    const wchar_t *paymentIndicator = 0;
    const wchar_t *formBundleNumber = 0;

    processingDate = jsonResponse.stringOf(L"processingDate");
    paymentIndicator = jsonResponse.stringOf(L"paymentIndicator");
    formBundleNumber = jsonResponse.stringOf(L"formBundleNumber");
    }

Sample JSON Response Body

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