Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Getting Error while generating IRN in business central cloud

Posted on by 73

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.

pastedimage1680853015242v1.png

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;

  • Suggested answer
    Marco Mels Profile Picture
    Marco Mels on at
    RE: Getting Error while generating IRN in business central cloud

    Hello,

    Feel free to raise this issue to Microsoft via your partner or CSP if you do not get further traction from the community. We may ask you for some sort of repro steps in standard.

    Thank you.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans