DataFlex 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'

DataFlex Example

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    Boolean iBTls
    Integer iPort
    Boolean iBAutoReconnect
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Integer iRespStatusCode
    Handle hoJsonResponse
    String sPeriodKey
    String sVatDueSales
    String sVatDueAcquisitions
    String sTotalVatDue
    String sVatReclaimedCurrPeriod
    String sNetVatDue
    Integer iTotalValueSalesExVAT
    Integer iTotalValuePurchasesExVAT
    Integer iTotalValueGoodsSuppliedExVAT
    Integer iTotalAcquisitionsExVAT
    String sTemp1
    Integer iTemp1

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    //  URL: https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/returns/A001
    Move True To iBTls
    Move 443 To iPort
    Move True To iBAutoReconnect
    Get ComConnect Of hoRest "test-api.service.hmrc.gov.uk" iPort iBTls iBAutoReconnect To iSuccess
    If (iSuccess <> True) Begin
        Get ComConnectFailReason Of hoRest To iTemp1
        Showln "ConnectFailReason: " iTemp1
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComAddHeader Of hoRest "Authorization" "Bearer HMRC_ACCESS_TOKEN" To iSuccess
    Get ComAddHeader Of hoRest "Accept" "application/vnd.hmrc.1.0+json" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComFullRequestNoBodySb Of hoRest "GET" "/organisations/vat/MY_HMRC_VRN/returns/A001" vSbResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComResponseStatusCode Of hoRest To iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Status Code = " iRespStatusCode
        Showln "Response Header:"
        Get ComResponseHeader Of hoRest To sTemp1
        Showln sTemp1
        Showln "Response Body:"
        Get ComGetAsString Of hoSbResponseBody To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResponse
    If (Not(IsComObjectCreated(hoJsonResponse))) Begin
        Send CreateComObject of hoJsonResponse
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJsonResponse vSbResponseBody To iSuccess

    //  See the Online Tool for Generating JSON Parse Code

    Get ComStringOf Of hoJsonResponse "periodKey" To sPeriodKey
    Get ComStringOf Of hoJsonResponse "vatDueSales" To sVatDueSales
    Get ComStringOf Of hoJsonResponse "vatDueAcquisitions" To sVatDueAcquisitions
    Get ComStringOf Of hoJsonResponse "totalVatDue" To sTotalVatDue
    Get ComStringOf Of hoJsonResponse "vatReclaimedCurrPeriod" To sVatReclaimedCurrPeriod
    Get ComStringOf Of hoJsonResponse "netVatDue" To sNetVatDue
    Get ComIntOf Of hoJsonResponse "totalValueSalesExVAT" To iTotalValueSalesExVAT
    Get ComIntOf Of hoJsonResponse "totalValuePurchasesExVAT" To iTotalValuePurchasesExVAT
    Get ComIntOf Of hoJsonResponse "totalValueGoodsSuppliedExVAT" To iTotalValueGoodsSuppliedExVAT
    Get ComIntOf Of hoJsonResponse "totalAcquisitionsExVAT" To iTotalAcquisitionsExVAT


End_Procedure

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
}