I am trying to use the Delphi TREST components to connect to the HRMC VAT API.
I have got as far as obtaining access and refresh tokens, but I cannot get any further.
At the moment, I am trying to retrieve my obligations as follows:-
RESTClient := TRestClient.Create('https://test-api.service.hmrc.gov.uk/organisations/vat/666596898/obligations');
try
RESTRequest := TRESTRequest.Create(RESTClient);
RESTResponse := TRESTResponse.Create(RESTClient);
OAuth2 := TOAuth2Authenticator.Create(RESTClient);
with OAuth2 do
begin
AccessToken := <my access token>;
ResponseType := TOAuth2ResponseType(rtCODE);
TokenType := TOAuth2TokenType(ttBEARER);
end;
with RESTClient do
begin
Authenticator := OAuth2;
ContentType := 'application/json';
end;
with RESTRequest do
begin
Client := RESTClient;
Response := RESTResponse;
Accept := 'application/vnd.hmrc.1.0+json';
Params.AddItem('from', '2017-01-25', pkGETorPOST);
Params.AddItem('to', '2017-01-25', pkGETorPOST);
Execute;
end;
finally
RESTClient.DisposeOf;
end;
This particular code returns the error INVALID_DATE_RANGE. But depending on what dates I use, I also sometimes get CLIENT_OR_AGENT_NOT_AUTHORISED.
Can anyone shed any light on where I am going wrong?