HMRC VAT API Invalid_Date_Range - api

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?

Perhaps it doesn't like the start and end dates being the same? It does say invalid date RANGE rather than invalid dates.

I worked it out finally. It was a problem with my Test User credentials. I generated them from the HMRC website, but I discovered from other posts that there is a problem generating them that way. When I created a user via the API, it works fine!
I hope this helps someone.

Related

What means a static response from an API and Sandbox?

I am working for the first time with API-s. My first task at my job is to call an API, I am working with the Sandbox version of the API
I am trying to call the Sandbox this way and I should get a static response, but I am getting
"Error at message validation"
what means this and what exactly is a Sandbox and what is a static response?
procedure consentrequest(out transactionid1:transactionIdType);
var
Httprio2 : THTTPRio;
initiateConsentRequest1 : initiateConsentRequest;
initiateconsentrequestresponse1 : initiateconsentrequestresponse;
type2 :consenttype;
consent_init : consent2;
//AccountInfo_PT2 : AccountInfo_PT;
//transactionId1 : transactionIdType;
begin
initiateConsentRequest1 :=initiateConsentRequest.Create;
initiateconsentrequestresponse1 :=initiateconsentrequestresponse.Create;
consent_init :=consent2.Create;
HTTPRio2 :=THTTPRIO.Create(nil);
HTTPRio2.Url := 'https://sandbox.budapestbank.hu/OpenapiSandbox/v1.0.0';
consent_init.type_ :=type2;
consent_init.target := 'HU12345678901234567890123456';
consent_init.validityPeriod :=30;
initiateConsentRequest1.consent :=consent_init;
ShowMessage('Before PT');
initiateconsentrequestresponse1 :=(HTTPRio2 as AccountInfo_PT).initiateConsentRequest(initiateConsentRequest1);
ShowMessage('After PT');
transactionid1 := initiateconsentrequestresponse1.transactionId;
end;
A Sandbox is usually a non-production copy of the API, you might use different creds and get sample data responses. It's a safe practice space for developers.
The error about "message validation" makes me think that the API request you sent was somehow invalid, perhaps it is missing a parameter. Check the docs of the API you are calling and make sure you have the correct verb/endpoint and parameters. Also see if there is more information in the response itself.

Authentication - PLS-00488: 'VALIDATE_USER_FROM_DB' must be a type ORA-06550

I'm currently working on an application in Oracle Application Express 5, more specifically I'm trying to create a custom authentication scheme.
I started by creating a function in the SQL command window that would provide my application with a basic level of authentication. I want my users to be able to sign in with their personal student reference number (srn) and date of birth (dob) and this information is taken from the table "student".
create or replace function validate_user_from_db
(p_username in number, p_password in date)
return boolean
as v_pw_check varchar2(1);
begin select 'x' into v_pw_check
from student
where upper(srn) = upper(p_username)
and dob = p_password; apex_util.set_authentication_result(0);
return true; exception when no_data_found then apex_util.set_authentication_result(4);
return false;
end validate_user_from_db;
This function compiled with no errors and so I then went on to create a simple query that would test the function.
declare
vresult varchar2(10);
begin
if validate_user_from_db ('30134852', '08/17/1997') then
DBMS_OUTPUT.PUT_LINE('Welcome Back');
else
DBMS_OUTPUT.PUT_LINE('Error');
end if;
end;
The query was successful and was outputting "Welcome Back" when the correct credentials were filled. Now that everything was working how I'd hoped I went about creating a new authentication scheme. I named it "User Validation" and set the scheme type to custom.
I've been following a tutorial and researching into authentication schemes and it was suggested that in the PL/SQL code I place the line,
return validate_user_from_db;
but when I saved and compiled it I got this error message.
Error Code
In attempt to try and resolve this issue I decided to write the following function in PL/SQL code window and it compiled without any issues, but when I try run the application and use correct login credentials it just hits me with an error message stating "Invalid Login Credentials".
function validate_user_from_db
(p_username in number, p_password in date)
return boolean
as v_pw_check varchar2(1);
begin select 'x' into v_pw_check
from student
where upper(srn) = upper(p_username)
and dob = p_password; apex_util.set_authentication_result(0);
return true; exception when no_data_found then apex_util.set_authentication_result(4);
return false;
end validate_user_from_db;
Any help will be much appreciated as this is my firs time creating authentication with Oracle Apex.
I resolved the issue after messing around with a test application. Turns out a login page is automatically generated depending on the authentication scheme you have set in place. Make sure you delete your existing login page when you change authentication.

How to use http.Get in a TLSClient in Go?

Hi I want to perform a GET Request in GO after creating a tlsclient, for example:
client, err := docker.NewTLSClient(sconf.DockConf.Endpoint, sconf.DockConf.Cert, sconf.DockConf.Key, sconf.DockConf.Ca)
then how can I perform a Get request in GO?
Not sure what package you are using but the http package has a NewRequest function
req, _ := http.NewRequest("GET", url, nil)
client.Do(req)
--Edit
In addition, here is a full working TLS example with client certificates (I did not create this gist)
https://gist.github.com/michaljemala/d6f4e01c4834bf47a9c4

I would like to know about the implementation of sending an SMS through oracle pl/Sql

I would like to know about the implementation of sending an SMS through oracle pl/Sql.If any one who has developed please provide an input.
This should give you some ideas, using this function i can send sms using soap api of sms service, you should tune it using your soap envelope, response, ip wallet etc.
Input should be xml data according to your service putted together with envelope - you need to consult this with your provider.
Of course if you user modern oracle you should ensure about ACL for IP and network access as well as encryption for your connection
function send(message_data in varchar2) return varchar2 is
/**************************************************
* author: jareeq
* use as you like
***************************************************/
resp sys.xmltype;
http_req utl_http.req;
http_resp utl_http.resp;
soap_request clob;
soap_respond clob;
v_result varchar2(4096);
v_buffer_varchar varchar2(4096);
begin
/* wallet for https con */
UTL_HTTP.set_wallet('file:/xxx/xxx/xxx/wallets', '************');
soap_request := '<your soap envelope here>';
utl_http.set_response_error_check(TRUE);
http_req := utl_http.begin_request('https://<your service request>',
'POST', 'HTTP/1.1');
utl_http.set_header(http_req, 'Content-Type',
'application/xop+xml; type=text/xml; charset=utf-8');
utl_http.set_header(http_req, 'Content-Length', length(soap_request));
utl_http.write_text(http_req, soap_request);
http_resp := utl_http.get_response(http_req);
begin
loop
utl_http.read_text(http_resp, v_buffer_varchar);
soap_respond := soap_respond || v_buffer_varchar;
end loop;
utl_http.end_response(http_resp);
exception
when utl_http.end_of_body then
utl_http.end_response(http_resp);
end;
utl_http.close_persistent_conns('<your connection ip>', 443);
resp := sys.xmltype.createXML(soap_respond);
v_result := resp.extract('<your extraction path>')
.getStringVal();
return replace(replace(v_result,chr(10)),chr(13));
exception
when utl_http.end_of_body then
utl_http.end_response(http_resp);
utl_http.close_persistent_conns('<your connection ip>', 443);
return replace(replace(v_result,chr(10)),chr(13));
end send;
Unlike email, Oracle provides no API for sending messages via SMS. However, you can use UTL_HTTP to send requests to an SMS Gateway, depending on what types of APIs they offer you. You will find some offer HTTP, SOAP, and Rest-style APIs, as well as Email-to-SMS.
Personally I use a local gateway here in Australia (ClickSend) that suits my needs. They offer a REST-style API which is quite easy to call using UTL_HTTP.
Find a gateway that suits your needs and budget first. They vary as well in quality of service - some are just Tier 2 aggregators so SMS's can take a while to get through; Tier 1 will have direct connections or premium agreements with a number of mobile carriers for fast delivery.

Delphi REST client can't create event in Google Calendar - Parse Error

I realise that there's a duplicate question, but it wasn't answered, so I'm raising the question again with my own code that doesn't work.
I'm trying to send HTTP requests to the Google Calendar/v3 API using the REST client library components in DELPHI XE5 Update 2 (TRESTClient, TRESTRequest, TRESToAuth2Autenticator, TRESTResponse).
Why doesn't the following work? All I get is a Bad Request stating "This API does not support parsing form-encoded input". I have specified application/json in the Client and the Request, yet it is ignoring this and still sending as Form Encoded.
JB := TlkJSONObject.Create;
JBStart := TlkJSONObject.Create;
JBEnd := TlkJSONObject.Create;
try
JB.Add('Summary', 'Another Test');
JBStart.Add('DateTime', '2016-02-09T17:00:00');
JBStart.Add('TimeZone', 'Europe/London');
JB.Add('Start', JBStart);
JBEnd.Add('DateTime', '2016-02-09T18:00:00');
JBEnd.Add('TimeZone', 'Europe/London');
JB.Add('End', JBEnd);
Event := TlkJSON.GenerateText(JB);
finally
FreeAndNil(JB);
end;
Client.BaseURL := 'https://www.googleapis.com/calendar/v3/calendars/' + CalID + '/events?key=' + ClientInfo.APIKey;
Client.ContentType := 'application/json;';
Req.AddBody(Event, ctAPPLICATION_JSON);
Req.Method := rmPOST;
Req.Execute;