Visual FoxPro HMRC VAT MTD: Retrieve VAT obligations

Back to Index

Retrieve VAT obligations

Documentation: https://developer.service.hmrc.gov.uk/api-documentation/docs/api/service/vat-api/1.0#_retrieve-vat-obligations_get_accordion

CURL Command

curl -X GET  https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/obligations?from=2018-06-25&to=2019-01-01 \
-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 i
LOCAL lnCount_i
LOCAL lcStart
LOCAL lcEnd
LOCAL lcDue
LOCAL lcStatus
LOCAL lcPeriodKey
LOCAL lcReceived

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/obligations?from=2018-06-25&to=2019-01-01
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/obligations?from=2018-06-25&to=2019-01-01",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

i = 0
lnCount_i = loJsonResponse.SizeOfArray("obligations")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcStart = loJsonResponse.StringOf("obligations[i].start")
    lcEnd = loJsonResponse.StringOf("obligations[i].end")
    lcDue = loJsonResponse.StringOf("obligations[i].due")
    lcStatus = loJsonResponse.StringOf("obligations[i].status")
    lcPeriodKey = loJsonResponse.StringOf("obligations[i].periodKey")
    lcReceived = loJsonResponse.StringOf("obligations[i].received")
    i = i + 1
ENDDO

RELEASE loRest
RELEASE loSbResponseBody
RELEASE loJsonResponse

Sample JSON Response Body

{
  "obligations": [
    {
      "start": "2017-01-01",
      "end": "2017-03-31",
      "due": "2017-05-07",
      "status": "F",
      "periodKey": "18A1",
      "received": "2017-05-06"
    },
    {
      "start": "2017-04-01",
      "end": "2017-06-30",
      "due": "2017-08-07",
      "status": "O",
      "periodKey": "18A2"
    }
  ]
}