Showing posts with label API Integration. Show all posts
Showing posts with label API Integration. Show all posts

Friday, July 14, 2023

API Calling Post Method Most Common Error - misused header name 'authorization' business central

 Hello Friend

You must face below error while you try to call API post method with mullitple header value

misused header name 'authorization' business centra
















This error come because of invalid content type handle in API call

Below example you can see where we need to pass 2 header value


















BC Working Code:

           action("Chat GTP")
            {
                ApplicationArea = Suite;
                Caption = 'Chat GTP';
                Image = Production;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                PromotedOnly = true;

                trigger OnAction()
                var
                    myInt: Integer;
                    Gpt_JsonObject_L: JsonObject;
                    Gpt_JsonText_L: Text;
                    Content: HttpContent;
                    Client: HttpClient;
                    Headers: HttpHeaders;
                    Request: HttpRequestMessage;
                    Response: HttpResponseMessage;
                    JSONResponse: Text;
                    JObject: JsonObject;
                begin

                    Gpt_JsonObject_L.Add('model', 'text-davinci-003');
                    Gpt_JsonObject_L.Add('prompt', 'how are you?');
                    Gpt_JsonObject_L.Add('temperature', 0.2);
                    Gpt_JsonObject_L.WriteTo(Gpt_JsonText_L);

                    Request.Method := 'POST';
                    Request.SetRequestUri('https://api.openai.com/v1/completions');

                    Headers.Clear();
                    Request.GetHeaders(Headers);
                    Headers.Add('Authorization', 'Bearer ' + 'sk-FxpqNnCvf1qTbz0m1EXGT
3BlbkFJ6B7V3oIcHHKnjs1N4c6O');
                    Content.WriteFrom(Gpt_JsonText_L);

                    Content.GetHeaders(Headers);
                    Headers.Remove('Content-Type');
                    Headers.Add('Content-Type', 'application/json');
                    Request.Content := Content;

                    if not Client.Send(Request, Response) then
                        Error('API Authorization token request failed...');

                    JSONResponse := '';
                    Response.Content().ReadAs(JSONResponse);

                    if not JObject.ReadFrom(JSONResponse) then
                        Error('Invalid response, expected a JSON object');

                    Message(JSONResponse);

                end;

Response will show in msg




















To lear more watch this video:

https://www.youtube.com/watch?v=QmCXUm0bEfU

I hope this help someone

Thank you for reading.

Keep Sharing....Keep Growing....

Friday, May 13, 2022

API Base Cloud Printing in Business Central SaaS Version

Hello Friends,

It was very demanding in Business Central Cloud version to allow user to print directly from BC / Mobile App / Tablet App.

This can only be possible using Cloud API for printing.

We have develop very advance cloud printing API utility for print any Report by just single click from Business Central - any version.









procedure GetBase64_DS(ReportID: Integer; RecRef: RecordRef)
    var
        APISetup_lRec: Record "Cloud Print API Setup";
        ReportPrinterSetup: Record "Report Printer Setup";
        Base64Convert: Codeunit "Base64 Convert";
        Rpt_TempBlob: Codeunit "Temp Blob";
        gHttpClient: HttpClient;
        gcontent: HttpContent;
        lheaders: HttpHeaders;
        greqMsg: HttpRequestMessage;
        gResponseMsg: HttpResponseMessage;
        Rpt_InStream: InStream;
        DuplexPrintOption_lInt: Integer;
        ReqJObject: JsonObject;
        Rpt_OutStream: OutStream;
        Base64String: Text;
        JSONResponse: Text;
        ltext: Text;
        lurl: Text;
        PDFCMDBase64_lTxt: Text;
        PrintCmdText: Text;
        PrinterName_iTxt: Text;
        ReportFileName_lTxt: Text;
    begin
        APISetup_lRec.GET;
        APISetup_lRec.Testfield("Exe Path");
        APISetup_lRec.Testfield("Folder Path");
        APISetup_lRec.Testfield("Print API");

        ReportPrinterSetup.Reset();
        ReportPrinterSetup.SetRange("User ID", UserId);
        ReportPrinterSetup.SetRange("Report ID", ReportID);
        IF ReportPrinterSetup.FindFirst() THEN begin
            DuplexPrintOption_lInt := ReportPrinterSetup."Print Duplex Mode" + 1;
            PrinterName_iTxt := ReportPrinterSetup."Printer Name"
        End Else begin
            ReportPrinterSetup.SetRange("Report ID", 0);
            IF ReportPrinterSetup.FindFirst() THEN begin
                DuplexPrintOption_lInt := ReportPrinterSetup."Print Duplex Mode" + 1;
                PrinterName_iTxt := ReportPrinterSetup."Printer Name";
            End;
        end;


        Rpt_TempBlob.CreateOutStream(Rpt_OutStream);
        Report.SaveAs(ReportID, RecRef.GetFilters(), ReportFormat::Pdf,
Rpt_OutStream, RecRef);
        Rpt_TempBlob.CreateInStream(Rpt_InStream);
        Base64String := Base64Convert.ToBase64(Rpt_InStream);

        ReportFileName_lTxt := 'Inv_' + FORMAT(CURRENTDATETIME, 0,
'<Day,2>_<Month,2>_<Year4>_<Hours24>_<Minutes,2>_<Seconds,2>') + '_' +
Format(Random(100)) + '.pdf';

        PrintCmdText := StrSubstNo('%1 -duplex %2 -printer "%3" %4%5',
APISetup_lRec."Exe Path", DuplexPrintOption_lInt, PrinterName_iTxt,
APISetup_lRec."Folder Path", ReportFileName_lTxt);

        PDFCMDBase64_lTxt := Base64Convert.ToBase64(PrintCmdText);

        ReqJObject.Add('ReportBase64', Base64String);
        ReqJObject.Add('PrintCMDCommand', PDFCMDBase64_lTxt);
        ReqJObject.Add('FileName', ReportFileName_lTxt);
        ReqJObject.Add('FolderPath', Base64Convert.ToBase64(APISetup_lRec."Folder Path"));
        ReqJObject.Add('Exepath', Base64Convert.ToBase64(APISetup_lRec."Exe Path"));
        ReqJObject.WriteTo(ltext);

        lurl := APISetup_lRec."Print API";

        gcontent.WriteFrom(ltext);
        greqMsg.SetRequestUri(lurl);
        lheaders.Clear();
        gcontent.GetHeaders(lheaders);

        lheaders.Remove('Content-Type');
        lheaders.Add('Content-Type', 'application/json');
        gcontent.GetHeaders(lheaders);
        greqMsg.Content(gcontent);
        greqMsg.GetHeaders(lheaders);
        greqMsg.Method := 'POST';
        if not gHttpClient.Send(greqMsg, gResponseMsg) then
            Error('API Authorization token request failed...');

        JSONResponse := '';
        gResponseMsg.Content().ReadAs(JSONResponse);


        IF STRPOS(JSONResponse, 'An error has occurred') <> 0 then
            Error('Error %1 \\ PDF Command (in Base64) %2', JSONResponse, PDFCMDBase64_lTxt);

        IF STRPOS(JSONResponse, 'Time of printing is:') <> 0 then
            Message('Document Print Successfully')
        Else
            Message(JSONResponse);
    end;
}

Done...

This will print any report in just single click - where user can setup Default printer name in Business Central

Also this utility provide advance command of print like - Simple / Duplex Print and Paper Source Selection.

New Revaluation of Printing in cloud application !!!

If you intrested to purcahse this utility than contact to Intech System.

Thank you for reading....

Keep Sharing...Keep Growing...


Physical Token base Digital Singnature with Business Central SaaS Version

Hello Friends,

Digital Singnature is very demanding request with Business Central SaaS Version

It was compare to develope very easy for BC On Prime or NAV Version - where we have local system full access.

For any cloud application it is quite challening. 

At Intech we dp the development using Windows Application in .Net

Develop very useful utility that can connect to BC using API and provide facitlty for Digital Signature

Key Feature of Digital Signature Utility

  • Sign Single Document
  • Bulk Sign Documents
  • Sign and attach signed document in ERP
  • Sign and Email to Customer/Vendor
  • Sign and attach to ERP & Email to Customer/Vendor

Snapshot of Utility Developed:




If you intrested in solution than let connect to Intech Systems.
Thank you.


Thursday, April 21, 2022

Create Json Body - Multiple Level and Send Using HPPT Request in Business Central

Hello Friends,

Below is sample code to create multiple level Json Body Objects and send it on HTTP Request

Json Sample Body - need to generate:

{
        "type""media-notification",
        "mime""application/pdf",
        "link": http://454.356.45.467:7146/Attachment/OrderEntry_19_01_2022_17_00_01_2955.pdf,
        "body": {
            "to""919758642372",
            "ttl"200000,
            "type""template",
            "template": {
                "namespace""11382ca3_9ff1_467f_acab_c722c0920145",
                "language": {
                    "policy""deterministic",
                    "code""en"
                },
                "name""sales_invoice_update",
                "components": [
                    {
                        "type""header",
                        "parameters": [
                            {
                                "type""document",
                                "document": {
                                    "filename""Business-portal-connector-EULA.pdf"
                                }
                            }
                        ]
                    },
                    {
                        "type""body",
                        "parameters": [
                            {
                                "type""text",
                                "text""test"
                            },{
                                "type""text",
                                "text""{{text2}}"
                            },{
                                "type""text",
                                "text""{{text3}}"
                            },{
                                "type""text",
                                "text""{{text4}}"
                            },{
                                "type""text",
                                "text""{{text5}}"
                            },{
                                "type""text",
                                "text""{{text6}}"
                            }
                        ]
                    }
                ]
            }
        }
    }
================
Business Central AL Extension Code to Create Above body and send on HTTP Request

codeunit 76676 APIMgmt
{
    PROCEDURE TestWhatsapp(): Boolean
    VAR
        Win_lDlg: Dialog;


        FinalJobject: JsonObject;
        bodyJobject: JsonObject;
        templateJobject: JsonObject;
        languageJobject: JsonObject;
        componentsJArray: JsonArray;
        componentsHeaderJObject: JsonObject;
        componentsBodyJObject: JsonObject;
        parametersJArray: JsonArray;
        parametersJObject: JsonObject;
        DocumentJObject: JsonObject;
        parametersBodyJArray: JsonArray;
        parametersBodyJObject: JsonObject;

        ltext: Text;
        lheaders: HttpHeaders;
        lurl: Text;
        gcontent: HttpContent;
        gHttpClient: HttpClient;
        gheaders: HttpHeaders;
        greqMsg: HttpRequestMessage;
        gResponseMsg: HttpResponseMessage;
        JSONResponse: Text;
        JObject: JsonObject;
        Jtoken: JsonToken;
        JValue: JsonValue;

    BEGIN

        IF NOT CONFIRM('Do you want to Create API?', FALSE) THEN
            EXIT;

        Win_lDlg.OPEN('Processing...');

        Clear(FinalJobject);
        Clear(bodyJobject);
        Clear(templateJobject);
        Clear(languageJobject);
        Clear(componentsJArray);
        Clear(componentsHeaderJObject);
        Clear(componentsBodyJObject);
        Clear(parametersJArray);
        Clear(parametersJObject);
        Clear(DocumentJObject);
        Clear(parametersBodyJArray);
        Clear(parametersBodyJObject);

        //Main Body Objects
        FinalJobject.Add('type', 'media-notification');
        FinalJobject.Add('mime', 'application/pdf');
        FinalJobject.Add('link', 'http://XXXX.....1960_01_2955.pdf');

        //Body Objects
        bodyJobject.Add('to', '919426481901');
        bodyJobject.Add('ttl', 200000);
        bodyJobject.Add('type', 'template');

        templateJobject.Add('namespace', '11382ca3_9ff1_445f_acab_c722c0920173');

        languageJobject.Add('policy', 'deterministic');
        languageJobject.Add('code', 'en');

        templateJobject.Add('language', languageJobject);
        templateJobject.Add('name', 'sales_invoice_update');

        //Header Component
        componentsHeaderJObject.Add('type', 'header');
        parametersJObject.Add('type', 'document');
        DocumentJObject.Add('filename', 'Business-portal-connector-EULA.pdf');
        parametersJObject.add('document', DocumentJObject);
        parametersJArray.Add(parametersJObject);
        componentsHeaderJObject.Add('parameters', parametersJArray);

        componentsBodyJObject.Add('type', 'body');
        Clear(parametersBodyJObject);
        parametersBodyJObject.Add('type', 'text');
        parametersBodyJObject.Add('text', 'test');
        parametersBodyJArray.Add(parametersBodyJObject);
        Clear(parametersBodyJObject);
        parametersBodyJObject.Add('type', 'text');
        parametersBodyJObject.Add('text', '{{test2}}');
        parametersBodyJArray.Add(parametersBodyJObject);
        Clear(parametersBodyJObject);
        parametersBodyJObject.Add('type', 'text');
        parametersBodyJObject.Add('text', '{{test3}}');
        parametersBodyJArray.Add(parametersBodyJObject);
        Clear(parametersBodyJObject);
        parametersBodyJObject.Add('type', 'text');
        parametersBodyJObject.Add('text', '{{test4}}');
        parametersBodyJArray.Add(parametersBodyJObject);
        Clear(parametersBodyJObject);
        parametersBodyJObject.Add('type', 'text');
        parametersBodyJObject.Add('text', '{{test5}}');
        parametersBodyJArray.Add(parametersBodyJObject);
        Clear(parametersBodyJObject);
        parametersBodyJObject.Add('type', 'text');
        parametersBodyJObject.Add('text', '{{test6}}');
        parametersBodyJArray.Add(parametersBodyJObject);


        componentsBodyJObject.Add('parameters', parametersBodyJArray);


        componentsJArray.Add(componentsHeaderJObject);
        componentsJArray.Add(componentsBodyJObject);
        templateJobject.Add('components', componentsJArray);
        bodyJobject.Add('template', templateJobject);
        FinalJobject.Add('body', bodyJobject);


        FinalJobject.WriteTo(ltext);

        MESSAGE(FORMAT(ltext));

        lurl := 'https://app.yellowmessenger.com/integr80225396';

        gcontent.WriteFrom(ltext);
        greqMsg.SetRequestUri(lurl);
        lheaders.Clear();
        gcontent.GetHeaders(lheaders);




        lheaders.Add('x-auth-token', '231910d304bcad66eeb83b3770');

        lheaders.Remove('Content-Type');
        lheaders.Add('Content-Type', 'application/json');
        gcontent.GetHeaders(lheaders);
        greqMsg.Content(gcontent);
        greqMsg.GetHeaders(lheaders);
        greqMsg.Method := 'POST';
        if not gHttpClient.Send(greqMsg, gResponseMsg) then
            Error('API Authorization token request failed...');

        JSONResponse := '';
        gResponseMsg.Content().ReadAs(JSONResponse);

        Message(JSONResponse);

        if not JObject.ReadFrom(JSONResponse) then
            Error('Invalid response, expected a JSON object');



        Win_lDlg.CLOSE;
        EXIT(TRUE);
    END;
}


That's it
It is very simple to create Json Object and send it on using HTTP Request

Thank you for reading...
Keep Sharing....Keep Growing....

Friday, September 10, 2021

Read Multiple Level Response in Business Cental AL Extension by Json Token, Json Object & Json Array

Dear Firends,

Use below sample code to read multiple array document respone in AL Extension

Sample AL Input File 



{
   "orders":[
      {
         "DocumentNo":"SO004349",
         "Status":"Partially Shipped",
         "lines":[
            {
               "LineNo":20000,
               "QtyToShip":1,
               "Status":"Finalised"
            }
         ]
      },
      {
         "DocumentNo":"SO004424",
         "Status":"Partially Shipped",
         "lines":[
            {
               "LineNo":10000,
               "QtyToShip":5,
               "Status":"Finalised"
            },
            {
               "LineNo":20000,
               "QtyToShip":5,
               "Status":"Finalised"
            }
         ]
      },
      {
         "DocumentNo":"SO004423",
         "Status":"Partially Shipped",
         "lines":[
            {
               "LineNo":10000,
               "QtyToShip":4,
               "Status":"Finalised"
            }
         ]
      }
   ]
}

AL Extensoin Code to Read Above File:

procedure UpdateSOShipmentStatus_gFnc(JsonText: Text)Boolean
    var
        SalesHeader_lRec: Record "Sales Header";
        SalesLine_lRec: Record "Sales Line";
        WarehouseShipLine_lRec: Record "Warehouse Shipment Line";
        Jtoken: JsonToken;
        JObject: JsonObject;
        jsonval: JsonValue;
        Jarray: JsonArray;
        i: Integer;
        j: Integer;
        TotalCount: Integer;
        OrderCount: Integer;
        Location_lRec: Record Location;
        ReqWareShip_lBln: Boolean;
        AnylineFound_lBln: Boolean;
    begin
        if not JObject.ReadFrom(JsonTextthen
            Error('Invalid response, expected a JSON object');

        JObject.Get('orders', Jtoken);

        if not Jarray.ReadFrom(Format(Jtoken)) then
            Error('Array not Reading Properly');

        TotalCount := 0;
        OrderCount := 0;
        TotalCount := Jarray.Count();
        for i := 0 to Jarray.Count() 1 do begin
            Jarray.Get(i, Jtoken);
            JObject := Jtoken.AsObject();

            Jtoken.AsObject.Get('DocumentNo', Jtoken);
            IF SalesHeader_lRec.GET(SalesHeader_lRec."Document Type"::Order, Jtoken.AsValue().AsCode()) then begin
                OrderCount += 1;

                Jarray.Get(i, Jtoken);
                if Jtoken.AsObject.Get('Status', Jtokenthen
                    SalesHeader_lRec."Shipment Status" := Jtoken.AsValue().AsText();

                JObject.Get('lines', Jtoken);
                for j := 0 to Jtoken.AsArray().Count() 1 do begin
                    JObject.Get('lines', Jtoken);
                    if Jtoken.AsArray().Get(j, Jtokenthen
                        Jtoken.AsObject.Get('LineNo', Jtoken);

                    if SalesLine_lRec.Get(SalesLine_lRec."Document Type"::Order, SalesHeader_lRec."No.", Jtoken.AsValue().AsInteger()) then begin
                        JObject.Get('lines', Jtoken);
                        if Jtoken.AsArray().Get(j, Jtokenthen
                            if Jtoken.AsObject.Get('QtyToShip', Jtokenthen begin
                                ReqWareShip_lBln := false;
                                IF Location_lRec.GET(SalesLine_lRec."Location Code"Then begin
                                    IF Location_lRec."Require Receive" Then begin
                                        ReqWareShip_lBln := true;
                                        WarehouseShipLine_lRec.RESET;
                                        WarehouseShipLine_lRec.Setrange("Source Type", 37);
                                        WarehouseShipLine_lRec.Setrange("Source Subtype", SalesLine_lRec."Document Type");
                                        WarehouseShipLine_lRec.Setrange("Source No.", SalesLine_lRec."Document No.");
                                        WarehouseShipLine_lRec.Setrange("Source Line No.", SalesLine_lRec."Line No.");
                                        IF WarehouseShipLine_lRec.FindFirst() Then begin
                                            IF WarehouseShipLine_lRec."Qty. Outstanding" <= Jtoken.AsValue().AsDecimal() THen
                                                WarehouseShipLine_lRec.Validate("Qty. to Ship", Jtoken.AsValue().AsDecimal())
                                            Else
                                                WarehouseShipLine_lRec.Validate("Qty. to Ship", WarehouseShipLine_lRec."Qty. Outstanding");

                                            WarehouseShipLine_lRec.Modify();
                                            AnylineFound_lBln := true;
                                        end;

                                    end;
                                end;
                                IF NOT ReqWareShip_lBln Then
                                    SalesLine_lRec.Validate("Qty. to Ship", Jtoken.AsValue().AsDecimal());
                            End;

                        JObject.Get('lines', Jtoken);
                        if Jtoken.AsArray().Get(j, Jtokenthen
                            if Jtoken.AsObject.Get('Status', Jtokenthen begin
                                SalesLine_lRec."Shipment Status" := Jtoken.AsValue().AsText();
                                SalesLine_lRec.Modify(true);
                                AnylineFound_lBln := true;

                                WarehouseShipLine_lRec.RESET;
                                WarehouseShipLine_lRec.Setrange("Source Type", 37);
                                WarehouseShipLine_lRec.Setrange("Source Subtype", SalesLine_lRec."Document Type");
                                WarehouseShipLine_lRec.Setrange("Source No.", SalesLine_lRec."Document No.");
                                WarehouseShipLine_lRec.Setrange("Source Line No.", SalesLine_lRec."Line No.");
                                IF WarehouseShipLine_lRec.FindFirst() Then begin
                                    WarehouseShipLine_lRec."Shipment Status" := SalesLine_lRec."Shipment Status";
                                    WarehouseShipLine_lRec.Modify();
                                    AnylineFound_lBln := true;
                                End;


                            end;
                    end;
                    SalesHeader_lRec.Modify(true);
                    AnylineFound_lBln := true;
                end;
            end;
        end;
        exit(AnylineFound_lBln);
    End;

========================================================================

New Example:

Simple single level Json Response:

{
    "access_token": "088e04b1-8efd-4491-a579-1cc4f07a7e68",
    "token_type": "bearer",
    "refresh_token": "cf822cb1-0b1e-48a4-aeda-db648b96d62a",
    "expires_in": 1479,
    "scope": "gstapi"
}
Reading AL code:

procedure ReadJson(JSONInput_iTxt: Text): TEXT
    var
        Jtoken: JsonToken;
        JObject: JsonObject;
        Customer_lRec: Record Customer;
        i: Integer;
        j: Integer;
        access_token: Text[100];
        token_type: Text[100];
        refresh_token: Text[100];
        expires_in: Text[80];
        scope: Guid;
        TotalCount: Integer;
        CustomerCount: Integer;
    begin
        If Not JObject.ReadFrom(JSONInput_iTxt) then
            Error('Invalid response, expected a JSON object');

        JObject.Get('access_token', Jtoken);
        access_token := Jtoken.AsValue().AsText();

        JObject.Get('token_type', Jtoken);
        token_type := Jtoken.AsValue().AsText();

        JObject.Get('refresh_token', Jtoken);
        refresh_token := Jtoken.AsValue().AsText();

        JObject.Get('expires_in', Jtoken);
        expires_in := Jtoken.AsValue().AsText();

        //JObject.Get('scope', Jtoken);
        //scope := Jtoken.AsValue().as();

        Exit(access_token);
    end;

=====================================================================

Second example where there are object inside Json Response

{
    "status": "1",
    "message": "Record Added Successfully",
    "data": {
        "docNum": "INVOICE00126",
        "ctin": "27GSPMH2101G1Z2",
        "docId": "612f4e83218788617684a121"
    }
}

Reading AL code:

 procedure ReadJosn(JsonText: Text): Boolean
    var
        Jtoken: JsonToken;
        JtokenInner: JsonToken;
        JObject: JsonObject;
        jsonval: JsonValue;
        Jarray: JsonArray;
        i: Integer;
        j: Integer;

        Status_lTxt: Text[30];
        Message_lTxt: Text[30];
        DocNum_lTxt: Text[30];
        CTIN_lTxt: Text[30];
        DocId_lTxt: Text[30];
    begin
        If Not JObject.ReadFrom(JsonText) then
            Error('Invalid response, expected a JSON object');

        if JObject.Get('status', Jtoken) then
            Status_lTxt := Jtoken.AsValue().AsText();

        if JObject.Get('message', Jtoken) then
            Message_lTxt := Jtoken.AsValue().AsText();

        JObject.Get('data', Jtoken);

        If Jtoken.AsObject().Get('docNum', JtokenInner) then
            DocNum_lTxt := JtokenInner.AsValue().AsText();

        If Jtoken.AsObject().Get('ctin', JtokenInner) then
            CTIN_lTxt := JtokenInner.AsValue().AsText();

        If Jtoken.AsObject().Get('docId', JtokenInner) then
            DocId_lTxt := JtokenInner.AsValue().AsText();

        Message(Status_lTxt, Message_lTxt, DocNum_lTxt, CTIN_lTxt, DocId_lTxt);
    end;

===========================

E-Invoice Response Read

{

    "invoices": [

        {

            "AckNo": 122610111383517,

            "AckDate": "2026-02-06 16:20:10",

            "Record": 1,

            "Success": false,

            "Fy": "202526",

            "Messages": "Duplicate IRN",

            "Status": "ERROR",

            "Irn": "8d150bd11436a6ee166e31680e1678ea38d4093932a50ed57e6a3790889f8084",

            "DocDtls": {

                "No": "DOC-NO/45253",

                "Dt": "31/01/2026",

                "Typ": "INV"

            },

            "SellerDtls": {

                "Gstin": "27AAKCM2754L1Z0"

            },

            "TranDtls": {

                "SupTyp": "B2B"

            },

            "CustDocNo": "DOC-NO/45253",

            "SignedQRCode": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjNCRTE3RTUxNDE5MjUyMjY0N0YwMUZEQkZGNTI3MUFENTI2OEQ3MzUiLCJ4NXQiOiJPLUYtVVVHU1VpWkg4Ql9iXzFKeHJWSm8xelUiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJOSUMgU2FuZGJveCIsImRhdGEiOiJ7XCJTZWxsZXJHc3RpblwiOlwiMjdBQUtDTTI3NTRMMVowXCIsXCJCdXllckdzdGluXCI6XCIwM0FBS0NNMjc1NEwxWkFcIixcIkRvY05vXCI6XCJET0MtTk8vNDUyNTNcIixcIkRvY1R5cFwiOlwiSU5WXCIsXCJEb2NEdFwiOlwiMzEvMDEvMjAyNlwiLFwiVG90SW52VmFsXCI6MTE4LFwiSXRlbUNudFwiOjEsXCJNYWluSHNuQ29kZVwiOlwiODQ3MTMwXCIsXCJJcm5cIjpcIjhkMTUwYmQxMTQzNmE2ZWUxNjZlMzE2ODBlMTY3OGVhMzhkNDA5MzkzMmE1MGVkNTdlNmEzNzkwODg5ZjgwODRcIixcIklybkR0XCI6XCIyMDI2LTAyLTA2IDE2OjIwOjEwXCJ9In0.RgKN_7aYdzyyzAFIOM4zsemZ33Aihx6iVzQNI_PdXZzW76NhkHA3rQgKevfJO-tF7soG6aTbXmK9hLMLJf06sfj3jmUXeSMVWVXjuLP1hcGmNEY3g2mpb9z_UbunsrjSOyijlSFJNukKn_UCtewCkfqeYI8-byYKql2EBZlWqiI_8XG-IlKqJDzw32yRNg3-Emz2koG1fie0fHbs0qKeehSLpOpNae8lHalcKY1JF0oR5KyZjF5fdmm6IVGwNC7iSqB-TVEP3BpBfSUbc-Ije-Im5b7-_hws5EOUyuhrrvWK8tNPFpnNwHmHIaA3POM6p3NmAO1o9KRcWx1hVT7o9w",

            "QrCode": "{\"SellerGstin\":\"27AAKCM2754L1Z0\",\"BuyerGstin\":\"03AAKCM2754L1ZA\",\"DocNo\":\"DOC-NO/45253\",\"DocTyp\":\"INV\",\"DocDt\":\"31/01/2026\",\"TotInvVal\":118,\"ItemCnt\":1,\"MainHsnCode\":\"847130\",\"Irn\":\"8d150bd11436a6ee166e31680e1678ea38d4093932a50ed57e6a3790889f8084\",\"IrnDt\":\"2026-02-06 16:20:10\"}",

            "EncodedId": "NDI0MTA4"

        }

    ]

}

FullAndFinalBody.WriteTo(ltext);

        IF EInvoiceSetup_gRec."Enable Sandbox Mode" THEN
            lurl := EInvoiceSetup_gRec."Sandbox E-Inv Generation API"
        ELSE
            lurl := EInvoiceSetup_gRec."E-Inv Generation API-URL";

        //NG-NS 040521
        IF EInvoiceSetup_gRec."Create Json File (OffLine)" THEN BEGIN
            Data_lTxt := FORMAT(ltext);
            FileName_ltxt := 'Sales Invoice_' + EInvoiceHeader_vRec.No;
            ExportAsJson(FileName_ltxt, ltext);
            EXIT;
        END;
        //NG-NE 040521

        // Message(ltext);
        IF EInvoiceSetup_gRec."Show Json Message for Debug" THEN
            MESSAGE(FORMAT(ltext));

        gcontent.WriteFrom(ltext);
        greqMsg.SetRequestUri(lurl);
        lheaders.Clear();
        gcontent.GetHeaders(lheaders);
        IF EInvoiceSetup_gRec."Enable Sandbox Mode" THEN BEGIN
            lheaders.Add('key', EInvoiceSetup_gRec."Sandbox Api Key");
        END ELSE BEGIN
            lheaders.Add('key', EInvoiceSetup_gRec."Production Api Key");
        END;
        lheaders.Remove('Content-Type');
        lheaders.Add('Content-Type', 'application/json');
        gcontent.GetHeaders(lheaders);
        greqMsg.Content(gcontent);
        greqMsg.GetHeaders(lheaders);

        greqMsg.Method := 'POST';
        if not gHttpClient.Send(greqMsg, gResponseMsg) then
            Error('API Authorization token request failed...');

        JSONResponse := '';
        gResponseMsg.Content().ReadAs(JSONResponse);

        if not JObject.ReadFrom(JSONResponse) then
            Error('Invalid response, expected a JSON object');

        if EInvoiceSetup_gRec."Show Json Message for Debug" then
            Message(JSONResponse);

        IF NOT JObject.Get('invoices', Jtoken) then
            Error(JSONResponse);

        if not Jarray.ReadFrom(Format(Jtoken)) then
            Error('Array not Reading Properly');

        Jarray.Get(0, Jtoken);  //Read First Value Only
        JObject := Jtoken.AsObject();

        ResponseStatus_lBln := false;
        if JObject.Get('Success', Jtoken) then begin
            if not Jtoken.AsValue().IsNull() then
                ResponseStatus_lBln := Jtoken.AsValue().AsBoolean();
        End;

        IF NOT ResponseStatus_lBln Then
            Error(JSONResponse);


        Jarray.Get(0, Jtoken);
        if JObject.Get('AckNo', Jtoken) then begin
            if not Jtoken.AsValue().IsNull() then
                AckNo_lTxt := Jtoken.AsValue().AsText();
        End;

        Jarray.Get(0, Jtoken);
        if JObject.Get('AckDate', Jtoken) then begin   //"2020-03-11 15:11:00"
            if not Jtoken.AsValue().IsNull() then
                AckDate_lTxt := Jtoken.AsValue().AsText();
        End;

        Jarray.Get(0, Jtoken);
        if JObject.Get('Irn', Jtoken) then begin
            if not Jtoken.AsValue().IsNull() then
                IRN_lTxt := Jtoken.AsValue().AsText();
        End;

        Jarray.Get(0, Jtoken);
        if JObject.Get('SignedQRCode', Jtoken) then begin
            if not Jtoken.AsValue().IsNull() then
                QRBase64String := Jtoken.AsValue().AsText();
        End;


        EInvoiceHeader_vRec.IRN := IRN_lTxt;
        EInvoiceHeader_vRec.AckNo := AckNo_lTxt;
        EInvoiceHeader_vRec.AckDate := AckDate_lTxt;  //"2020-03-11 15:11:00"
        //EInvoiceHeader_vRec.QrCodeImage := TempBlob.Blob;
        //GenrateQRCode(QRBase64String, EInvoiceHeader_vRec);
        if QRBase64String <> '' then begin
            Clear(TempBlob);
            Clear(RecordRef);
            Clear(FieldRef);
            EInvoiceHeader_vRec.Modify(True);
            RecordRef.Get(EInvoiceHeader_vRec.RecordId);
            QRGenerator.GenerateQRCodeImage(QRBase64String, TempBlob);
            FieldRef := RecordRef.Field(EInvoiceHeader_vRec.FieldNo(QrCodeImage));
            TempBlob.ToRecordRef(RecordRef, EInvoiceHeader_vRec.FieldNo(QrCodeImage));
            FieldRef := RecordRef.Field(EInvoiceHeader_vRec.FieldNo(QrCodeImage));
            EInvoiceHeader_vRec.QrCodeImage := FieldRef.Value;
        end;

        EInvoiceHeader_vRec.Status := EInvoiceHeader_vRec.Status::Generated;
        EInvoiceHeader_vRec.MODIFY(TRUE);

        CASE EInvoiceHeader_vRec."Document Type" OF
            EInvoiceHeader_vRec."Document Type"::"Sales Invoice":
                BEGIN
                    SIH_lRec.GET(EInvoiceHeader_vRec.No);
                    SIH_lRec."IRN Hash" := EInvoiceHeader_vRec.IRN;
                    SIH_lRec."Acknowledgement No." := EInvoiceHeader_vRec.AckNo;
                    SIH_lRec."Acknowledgement Date" := ConvertTextToDateTime_gFnc(EInvoiceHeader_vRec.AckDate, 2);
                    SIH_lRec."QR Code" := EInvoiceHeader_vRec.QrCodeImage;
                    SIH_lRec."E-Invoice Status" := EInvoiceHeader_vRec.Status;
                    SIH_lRec."E-Invoice Error" := FALSE;
                    SIH_lRec.MODIFY;
                END;
            EInvoiceHeader_vRec."Document Type"::"Sales Credit Memo":
                BEGIN
                    SCMH_lRec.GET(EInvoiceHeader_vRec.No);
                    SCMH_lRec."IRN Hash" := EInvoiceHeader_vRec.IRN;
                    SCMH_lRec."Acknowledgement No." := EInvoiceHeader_vRec.AckNo;
                    SCMH_lRec."Acknowledgement Date" := ConvertTextToDateTime_gFnc(EInvoiceHeader_vRec.AckDate, 2);
                    SCMH_lRec."QR Code" := EInvoiceHeader_vRec.QrCodeImage;
                    SCMH_lRec."E-Invoice Status" := EInvoiceHeader_vRec.Status;
                    SCMH_lRec."E-Invoice Error" := FALSE;
                    SCMH_lRec.MODIFY;
                END;
            EInvoiceHeader_vRec."Document Type"::"Purchase Credit Memo":
                BEGIN
                    PurchCrMemoHdr_lRec.GET(EInvoiceHeader_vRec.No);
                    PurchCrMemoHdr_lRec."IRN Hash" := EInvoiceHeader_vRec.IRN;
                    PurchCrMemoHdr_lRec."Acknowledgement No." := EInvoiceHeader_vRec.AckNo;
                    PurchCrMemoHdr_lRec."Acknowledgement Date" := ConvertTextToDateTime_gFnc(EInvoiceHeader_vRec.AckDate, 2);
                    PurchCrMemoHdr_lRec."QR Code" := EInvoiceHeader_vRec.QrCodeImage;
                    PurchCrMemoHdr_lRec."E-Invoice Status" := EInvoiceHeader_vRec.Status;
                    PurchCrMemoHdr_lRec."E-Invoice Error" := FALSE;
                    PurchCrMemoHdr_lRec.MODIFY;
                END;
            EInvoiceHeader_vRec."Document Type"::"Transfer Shipment":
                BEGIN

                END;
            EInvoiceHeader_vRec."Document Type"::"Service Invoice":
                BEGIN
                    SerIH_lRec.GET(EInvoiceHeader_vRec.No);
                    SerIH_lRec."IRN Hash" := EInvoiceHeader_vRec.IRN;
                    SerIH_lRec."Acknowledgement No." := EInvoiceHeader_vRec.AckNo;
                    SerIH_lRec."Acknowledgement Date" := ConvertTextToDateTime_gFnc(EInvoiceHeader_vRec.AckDate, 2);
                    SerIH_lRec."QR Code" := EInvoiceHeader_vRec.QrCodeImage;
                    SerIH_lRec."E-Invoice Status" := EInvoiceHeader_vRec.Status;
                    SerIH_lRec.MODIFY;
                END;
            EInvoiceHeader_vRec."Document Type"::"Service Credit Memo":
                BEGIN
                    SerCMHdr_lRec.GET(EInvoiceHeader_vRec.No);
                    SerCMHdr_lRec."IRN Hash" := EInvoiceHeader_vRec.IRN;
                    SerCMHdr_lRec."Acknowledgement No." := EInvoiceHeader_vRec.AckNo;
                    SerCMHdr_lRec."Acknowledgement Date" := ConvertTextToDateTime_gFnc(EInvoiceHeader_vRec.AckDate, 2);
                    SerCMHdr_lRec."QR Code" := EInvoiceHeader_vRec.QrCodeImage;
                    SerCMHdr_lRec."E-Invoice Status" := EInvoiceHeader_vRec.Status;
                    SerCMHdr_lRec."E-Invoice Error" := FALSE;
                    SerCMHdr_lRec.MODIFY;
                END;
            ELSE
                ERROR('Case not define for Document Type %1', EInvoiceHeader_vRec."Document Type");
        END;

=========================================

Reading below Response


























==============================