Retrieve VAT obligations
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'
integer li_rc
oleobject loo_Rest
integer li_Success
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_SbResponseBody
integer li_RespStatusCode
oleobject loo_JsonResponse
integer i
integer li_Count_i
string ls_Start
string ls_End
string ls_Due
string ls_Status
string ls_PeriodKey
string ls_Received
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
destroy loo_Rest
MessageBox("Error","Connecting to COM object failed")
return
end if
// URL: https://test-api.service.hmrc.gov.uk/organisations/vat/MY_HMRC_VRN/obligations?from=2018-06-25&to=2019-01-01
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("test-api.service.hmrc.gov.uk",li_Port,li_BTls,li_BAutoReconnect)
if li_Success <> 1 then
Write-Debug "ConnectFailReason: " + string(loo_Rest.ConnectFailReason)
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
return
end if
loo_Rest.AddHeader("Authorization","Bearer HMRC_ACCESS_TOKEN")
loo_Rest.AddHeader("Accept","application/vnd.hmrc.1.0+json")
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")
li_Success = loo_Rest.FullRequestNoBodySb("GET","/organisations/vat/MY_HMRC_VRN/obligations?from=2018-06-25&to=2019-01-01",loo_SbResponseBody)
if li_Success <> 1 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
destroy loo_SbResponseBody
return
end if
li_RespStatusCode = loo_Rest.ResponseStatusCode
if li_RespStatusCode >= 400 then
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
Write-Debug "Response Header:"
Write-Debug loo_Rest.ResponseHeader
Write-Debug "Response Body:"
Write-Debug loo_SbResponseBody.GetAsString()
destroy loo_Rest
destroy loo_SbResponseBody
return
end if
loo_JsonResponse = create oleobject
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat_9_5_0.JsonObject")
loo_JsonResponse.LoadSb(loo_SbResponseBody)
// See the Online Tool for Generating JSON Parse Code
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("obligations")
do while i < li_Count_i
loo_JsonResponse.I = i
ls_Start = loo_JsonResponse.StringOf("obligations[i].start")
ls_End = loo_JsonResponse.StringOf("obligations[i].end")
ls_Due = loo_JsonResponse.StringOf("obligations[i].due")
ls_Status = loo_JsonResponse.StringOf("obligations[i].status")
ls_PeriodKey = loo_JsonResponse.StringOf("obligations[i].periodKey")
ls_Received = loo_JsonResponse.StringOf("obligations[i].received")
i = i + 1
loop
destroy loo_Rest
destroy loo_SbResponseBody
destroy loo_JsonResponse
{
"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"
}
]
}