I have written the code in al for E-Invoice in that I have the authorization and uri everything then also the the frontend part the code throws the error of
local procedure GetTokenforEInvoice() ResponseText: Text
begin
Content.GetHeaders(contentHeaders);
RequestMessage.GetHeaders(RequestHeaders);
RequestHeaders.Add('gspappid', '87712B75AAE34C4F8DA3BC97BECFD209');
RequestHeaders.Add('gspappsecret', '1D410F73G5486G4E20GB673G1166661FC8B1');
RequestMessage.SetRequestUri('https://gsp.adaequare.com/gsp/authenticate?grant_type=token');
RequestMessage.Method('POST');
RequestMessage.Content(Content);
IsSuccessful := HttpClient.Send(RequestMessage, ResponseMessage);
if not IsSuccessful then
Message('An API call with the provided header has failed.')
else begin
ResponseMessage.Content.ReadAs(ResponseText);
// Message(ResponseText);
// Rec./Json Txt/ := ResponseText;
json_Object.ReadFrom(ResponseText);
if json_Object.Contains('access_token') then begin
json_Object.Get('access_token', json_Token);
json_value := json_Token.AsValue();
Tokenvalueastext := Format(json_value);
end;
String := Tokenvalueastext;
PostmanAccessTokenValue := DelChr(String, '=', '/');
Message(PostmanAccessTokenValue);
// RequestHeaders.Add('Authorization', 'Bearer ' + NewString);
end;
exit(PostmanAccessTokenValue);
end;
//Correct code for getting access token and checking authorization with Post Method on E-Invoice API integration - end
local procedure PostEInvoice() ResponseText: Text
var
posteinvoiceinstream: InStream;
begin
PostmanAccessTokenValue := GetTokenforEInvoice();
posteinvoiceinstream := convertblobtotext();
Content.WriteFrom(posteinvoiceinstream);
Content.GetHeaders(contentHeaders);
RequestMessage.GetHeaders(RequestHeaders);
RequestHeaders.Add('Authorization', 'Bearer ' + PostmanAccessTokenValue);
RequestHeaders.Add('user_name', 'adqgsphpusr1');
RequestHeaders.Add('password', 'Gsp@1234');
RequestHeaders.Add('gstin', '02AMBPG7773M002');
RequestHeaders.Add('requestid', '41bvj8kiqe8u56');
RequestMessage.SetRequestUri('https://gsp.adaequare.com/test/enriched/ei/api/invoice');
RequestMessage.Method('POST');
if ContentHeaders.Contains('Content-Type') then ContentHeaders.Remove('Content-Type');
ContentHeaders.Add('Content-Type', 'application/json');
RequestMessage.Content(Content);
IsSuccessful := HttpClient.Send(RequestMessage, ResponseMessage);
if not IsSuccessful then
Message('Status Code:%1// Reason : %2', ResponseMessage.HttpStatusCode, ResponseMessage.ReasonPhrase)
else begin
ResponseMessage.Content.ReadAs(ResponseText);
Message(ResponseText);
Rec./Json Txt/ := ResponseText;
end;
end;
trigger OnAfterGetRecord()
begin
LargeText := GetLargeText();
end;
/// <summary>
/// SetLargeText.
/// </summary>
/// <param name=/NewLargeText/>Text.</param>
procedure SetLargeText(NewLargeText: Text)
var
OutStream: OutStream;
begin
Clear(Rec./einvoice Txt/);
Rec./einvoice Txt/.CreateOutStream(OutStream, TEXTENCODING::UTF8);
OutStream.WriteText(LargeText);
Rec.Modify();
end;
/// <summary>
/// GetLargeText.
/// </summary>
/// <returns>Return variable NewLargeText of type Text.</returns>
procedure GetLargeText() NewLargeText: Text
var
TypeHelper: Codeunit /Type Helper/;
InStream: InStream;
begin
Rec.CalcFields(/einvoice Txt/);
Rec./einvoice Txt/.CreateInStream(InStream, TEXTENCODING::UTF8);
exit(TypeHelper.TryReadAsTextWithSepAndFieldErrMsg(InStream, TypeHelper.LFSeparator(), Rec.FieldName(/einvoice Txt/)));
end;
local procedure convertblobtotext() instream: InStream;
var
outstream: OutStream;
begin
Rec./einvoice Txt/.CreateInStream(instream);
exit(instream);
end;
Thank You,
Regards,
Shrey Chauhan