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

Tcl Example


load ./chilkat.dll

set rest [new_CkRest]

#  URL: https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/returns/A001
set bTls 1
set port 443
set bAutoReconnect 1
set success [CkRest_Connect $rest "test-api.service.hmrc.gov.uk" $port $bTls $bAutoReconnect]
if {[expr $success != 1]} then {
    puts "ConnectFailReason: [CkRest_get_ConnectFailReason $rest]"
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    exit
}

CkRest_AddHeader $rest "Authorization" "Bearer HMRC_ACCESS_TOKEN"
CkRest_AddHeader $rest "Accept" "application/vnd.hmrc.1.0+json"

set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestNoBodySb $rest "GET" "/organisations/vat/MY_HMRC_VRN/returns/A001" $sbResponseBody]
if {[expr $success != 1]} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkStringBuilder $sbResponseBody
    exit
}

set respStatusCode [CkRest_get_ResponseStatusCode $rest]
if {[expr $respStatusCode >= 400]} then {
    puts "Response Status Code = $respStatusCode"
    puts "Response Header:"
    puts [CkRest_responseHeader $rest]
    puts "Response Body:"
    puts [CkStringBuilder_getAsString $sbResponseBody]
    delete_CkRest $rest
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jsonResponse [new_CkJsonObject]

CkJsonObject_LoadSb $jsonResponse $sbResponseBody

#  See the Online Tool for Generating JSON Parse Code

set periodKey [CkJsonObject_stringOf $jsonResponse "periodKey"]
set vatDueSales [CkJsonObject_stringOf $jsonResponse "vatDueSales"]
set vatDueAcquisitions [CkJsonObject_stringOf $jsonResponse "vatDueAcquisitions"]
set totalVatDue [CkJsonObject_stringOf $jsonResponse "totalVatDue"]
set vatReclaimedCurrPeriod [CkJsonObject_stringOf $jsonResponse "vatReclaimedCurrPeriod"]
set netVatDue [CkJsonObject_stringOf $jsonResponse "netVatDue"]
set totalValueSalesExVAT [CkJsonObject_IntOf $jsonResponse "totalValueSalesExVAT"]
set totalValuePurchasesExVAT [CkJsonObject_IntOf $jsonResponse "totalValuePurchasesExVAT"]
set totalValueGoodsSuppliedExVAT [CkJsonObject_IntOf $jsonResponse "totalValueGoodsSuppliedExVAT"]
set totalAcquisitionsExVAT [CkJsonObject_IntOf $jsonResponse "totalAcquisitionsExVAT"]

delete_CkRest $rest
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $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
}