Visual FoxPro 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'

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJsonResponse
LOCAL lcPeriodKey
LOCAL lcVatDueSales
LOCAL lcVatDueAcquisitions
LOCAL lcTotalVatDue
LOCAL lcVatReclaimedCurrPeriod
LOCAL lcNetVatDue
LOCAL lnTotalValueSalesExVAT
LOCAL lnTotalValuePurchasesExVAT
LOCAL lnTotalValueGoodsSuppliedExVAT
LOCAL lnTotalAcquisitionsExVAT

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/returns/A001
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("test-api.service.hmrc.gov.uk",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

loRest.AddHeader("Authorization","Bearer HMRC_ACCESS_TOKEN")
loRest.AddHeader("Accept","application/vnd.hmrc.1.0+json")

loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/organisations/vat/MY_HMRC_VRN/returns/A001",loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loSbResponseBody
    CANCEL
ENDIF

lnRespStatusCode = loRest.ResponseStatusCode
IF (lnRespStatusCode >= 400) THEN
    ? "Response Status Code = " + STR(lnRespStatusCode)
    ? "Response Header:"
    ? loRest.ResponseHeader
    ? "Response Body:"
    ? loSbResponseBody.GetAsString()
    RELEASE loRest
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJsonResponse = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonResponse.LoadSb(loSbResponseBody)

*  See the Online Tool for Generating JSON Parse Code

lcPeriodKey = loJsonResponse.StringOf("periodKey")
lcVatDueSales = loJsonResponse.StringOf("vatDueSales")
lcVatDueAcquisitions = loJsonResponse.StringOf("vatDueAcquisitions")
lcTotalVatDue = loJsonResponse.StringOf("totalVatDue")
lcVatReclaimedCurrPeriod = loJsonResponse.StringOf("vatReclaimedCurrPeriod")
lcNetVatDue = loJsonResponse.StringOf("netVatDue")
lnTotalValueSalesExVAT = loJsonResponse.IntOf("totalValueSalesExVAT")
lnTotalValuePurchasesExVAT = loJsonResponse.IntOf("totalValuePurchasesExVAT")
lnTotalValueGoodsSuppliedExVAT = loJsonResponse.IntOf("totalValueGoodsSuppliedExVAT")
lnTotalAcquisitionsExVAT = loJsonResponse.IntOf("totalAcquisitionsExVAT")

RELEASE loRest
RELEASE loSbResponseBody
RELEASE loJsonResponse

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
}