Delphi DLL 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'

Delphi DLL Example

var
rest: HCkRest;
success: Boolean;
bTls: Boolean;
port: Integer;
bAutoReconnect: Boolean;
sbResponseBody: HCkStringBuilder;
respStatusCode: Integer;
jsonResponse: HCkJsonObject;
periodKey: PWideChar;
vatDueSales: PWideChar;
vatDueAcquisitions: PWideChar;
totalVatDue: PWideChar;
vatReclaimedCurrPeriod: PWideChar;
netVatDue: PWideChar;
totalValueSalesExVAT: Integer;
totalValuePurchasesExVAT: Integer;
totalValueGoodsSuppliedExVAT: Integer;
totalAcquisitionsExVAT: Integer;

begin
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) then
  begin
    Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(CkRest_getConnectFailReason(rest)));
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

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) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;
respStatusCode := CkRest_getResponseStatusCode(rest);
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkRest__responseHeader(rest));
    Memo1.Lines.Add('Response Body:');
    Memo1.Lines.Add(CkStringBuilder__getAsString(sbResponseBody));
    Exit;
  end;

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
}