Hello All,I have done customization to generate IRN for India localization in business central cloud ,but i'm getting below error while generating IRN. Below is my code .can anyone suggest me.
procedure AcquireToken(
): Text;
var
Client: HttpClient;
Request: HttpRequestMessage;
Response: HttpResponseMessage;
Content: HttpContent;
JAccessToken: JsonObject;
ContentHeaders: HttpHeaders;
//UriBuilder:DotNet UriBuilder;
ContentText: Text;
ResponseText: Text;
IsSuccess: Boolean;
Jtoken: JsonToken;
Json_Object: JsonObject;
ValueJtoken: JsonToken;
Rsp: Text;
begin
// ContentText :=
// 'gspappid' + '79536E39F216449883720CCD53643D8F' +
// 'gspappsecret' + 'EE5EFAACG8434G43E8GA90EG9660E98C3D71'
// ;
//Content.WriteFrom(ContentText);
Content.GetHeaders(ContentHeaders);
ContentHeaders.Remove('Content-Type');
ContentHeaders.Add('Content-Type', 'application/json');
ContentHeaders.Add('gspappid', 'xyx');
ContentHeaders.Add('gspappsecret', 'abc');
Request.Method := 'POST';
Content.GetHeaders(ContentHeaders);
//gsp.adaequare.com/.../invoice
Request.SetRequestUri('gsp.adaequare.com/.../authenticate
//Request.SetRequestUri('gsp.adaequare.com/.../authenticate
Request.Content(Content);
if Client.Send(Request, Response) then
if Response.IsSuccessStatusCode() then begin
if Response.Content.ReadAs(ResponseText) then
IsSuccess := JAccessToken.ReadFrom(ResponseText);
end else
if Response.Content.ReadAs(ResponseText) then
JAccessToken.ReadFrom(ResponseText);
Jtoken.ReadFrom(ResponseText);
if Jtoken.IsObject then begin
Json_Object := Jtoken.AsObject();
if Json_Object.Get('access_token', ValueJtoken) then begin
if ValueJtoken.IsValue then begin
Rsp := ValueJtoken.AsValue().AsText();
end;
end;
end;
exit(Rsp);
end;
procedure GenerateIRN(user_name: Text; password: Text; gstin: Code[15]; Authorization: Text; SalInvHdr: Record "Sales Invoice Header"): text
var
//IRNHttpWebRequestMgt: Codeunit 1297;
IRNHttpWebRequestMgt: HttpRequestMessage;
IRNPostUrl: Text;
contentHeaders: HttpHeaders;
content: HttpContent;
SInvNo: Text;
FilePath: Text;
FileName: Text;
IRNApiResult: Text;
IRNTempBlob: Codeunit "Temp Blob";
IRNInstr: InStream;
IRNResponseHeaders: HttpResponseMessage;
HttpResponse: HttpResponseMessage;
httpClient1: HttpClient;
fttt: Codeunit 1297;
hTTPhEADER: HttpHeaders;
Client: HttpClient;
Request: HttpRequestMessage;
Response: HttpResponseMessage;
//Content: HttpContent;
JAccessToken: JsonObject;
//ContentHeaders: HttpHeaders;
//UriBuilder:DotNet UriBuilder;
ContentText: Text;
ResponseText: Text;
IsSuccess: Boolean;
begin
//For BE
//IRNPostUrl:='gsp.adaequare.com/.../invoice';
//IRNPostUrl := 'gsp.adaequare.com/.../invoice';
content.WriteFrom(EinvJson);
Content.GetHeaders(ContentHeaders);
ContentHeaders.Remove('Content-Type');
ContentHeaders.Add('Content-Type', 'application/json;charset=UTF-8');
ContentHeaders.Add('user_name', user_name);
ContentHeaders.Add('password', password);
ContentHeaders.Add('gstin', gstin);
ContentHeaders.Add('requestid', GenerateReqId);
Content.GetHeaders(ContentHeaders);
//ContentHeaders.Add('Authorization', Authorization);
//client.DefaultRequestHeaders.Add('Content-Type', 'application/json; charset=utf-8');
client.DefaultRequestHeaders.Add('Authorization', Authorization);
Request.Method := 'POST';
Request.SetRequestUri('gsp.adaequare.com/.../invoice');
Request.Content(Content);
if Client.Send(Request, Response) then
if Response.IsSuccessStatusCode() then begin
if Response.Content.ReadAs(ResponseText) then
IsSuccess := JAccessToken.ReadFrom(ResponseText);
end else
if Response.Content.ReadAs(ResponseText) then
JAccessToken.ReadFrom(ResponseText);
Message(ResponseText);
exit(ResponseText);
end;