web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Submitting JSON to get the QR code with BC in AL code to the middleware to get QR code

(1) ShareShare
ReportReport
Posted on by 101
Dear Admin,
 
I think I am doing wrong by my  same request many times , because I dont have option.
 
1. I am  submitting my valid JSON file to a Middleware (http://192.xxx.yyyy:8080/elicensing/e-invoice/push-invoice
    with valid creditentials.
2. Response from above POSt should be having content like
   ({"responseId":"LT17502126658575712492886","responseDateTime":"20250618 06:11:05","requestId":"e3a1504e-fc90-4ce1-aac3-8de05ab6b315","status":"SUCCESS","environment":"TEST","infoMessages":null,"errorMessages":null,"fiscalisedInvoices":[{"invoiceIdentifier":"103253","irn":"STD28UD-2ed179f4-a147-33c0-a18d-b4b44c46fe0d","qrCode":"iVBORw0KGgoAAAANSUhEUgAAAV4AAAFeAQAAAADlUEq3AAAB7UlEQVR4Xu2YMa7CQAxEjSgoOUKOwtHI0XKUHIEyBcLfY+8u/kRCFLDbzBTE8j7TjOw4K/q57vKaeSPCWYSzCGcRziKcRTiLcFaBbxKaLHNQuS4W6MPOlnJwJdwfPvljmW4ng8GcN2lVqoSHwHfY9DxaBeXImLmoIjwOjqMq95TwaFi3oycgn3WEB8L+wNHxYWWX9e2sI9wFltB0wwsITA3KAeH+8FObxIhTtFUwTYSzfg6Hg+6XtZXOaCsbetFfyBDuD8d7xxhJbVW2AozB/21FuA+sOJoFTPqoMaEcVYTHwN5EiM0vYzxwB1/binAX2DNFBx9xLahWEu4PezcV4zDitH3U7NqKcCc4loFqouns15giBgdJeADcRhyM86Piqf8P4REwJhv2Z4dnia3AyssWR3gAXIxbpViJcl/exDOEx8BgFjhoAhOZUk54GCyX2l/GtKrqKeHuMPaxGcuAV8nkIw6olI4j3BtucitDWNWultm1VRPhrK/D/rqBcW4lhp7tzx5MuZxwVzgyC7oJTbREN7mDu7Yi3At++oXLmXIV467iZgBVhIfB5esmqnS+qG6oIDwe1rXOOvvZff4T7gT7A8bd4yqmXvhDhMfAEgrYA1iJtoqAcH/4MxHOIpxFOItwFuEswlmEs34I/wF8YFcMvQrPaQAAAABJRU5ErkJggg==","status":"SUCCESS","warningMessages":null,"errorMessages":null}]} )
3. from the above I can get QR code
 
I am not getting response. I need help with code how to POST/GET and How to collect the above message. I Request this is very urgent. 
Warm Regards
Kris
 
I have the same question (0)
  • Suggested answer
    Sohail Ahmed Profile Picture
    11,169 Super User 2026 Season 1 on at
    To successfully POST JSON to your middleware and retrieve the QR code, ensure your AL code correctly handles HttpContent and error checking.
     
    local procedure RequestQRCode2(InvoiceJsonData: Text): Text
    var
        MRsetup: Record LC_MRASetup;
        Client: HttpClient;
        RequestContent: HttpContent;
        Response: HttpResponseMessage;
        ResponseText: Text;
        JsonResponse: JsonObject;
        InvoicesToken: JsonToken;
        InvoicesArray: JsonArray;
        InvoiceObject: JsonObject;
        QRCodeValue: JsonToken;
        TempToken: JsonToken;
        ReqURL: Text;
    begin
        if not MRsetup.Get() then Error('MRA Setup not found.');
    
        ReqURL := MRsetup."Invoice Push URL";
        RequestContent.WriteFrom(InvoiceJsonData);
        RequestContent.GetHeaders().Clear(); // Crucial: Clear existing headers
        RequestContent.GetHeaders().Add('Content-Type', 'application/json');
    
        Client.DefaultRequestHeaders().Add('Authorization', 'Bearer ' + MRsetup."Bearer Token");
        Client.DefaultRequestHeaders().Add('Accept', 'application/json');
    
        // Check if the HTTP request itself failed
        if not Client.Post(ReqURL, RequestContent, Response) then
            Error('Failed to send HTTP POST request to middleware.');
    
        // Check middleware response status
        if not Response.IsSuccessStatusCode() then begin
            Response.Content().ReadAs(ResponseText);
            Error('Request failed: %1. Middleware Response: %2', Response.HttpStatusCode(), ResponseText);
        end;
    
        Response.Content().ReadAs(ResponseText); // Read successful response
        if not JsonResponse.ReadFrom(ResponseText) then
            Error('Invalid JSON received from middleware: %1', ResponseText);
    
        if JsonResponse.Get('fiscalisedInvoices', InvoicesToken) and InvoicesToken.IsArray() then begin
            InvoicesArray := InvoicesToken.AsArray();
            if InvoicesArray.Count > 0 and InvoicesArray.Get(0, TempToken) and TempToken.IsObject() then begin
                InvoiceObject := TempToken.AsObject();
                if InvoiceObject.Get('qrCode', QRCodeValue) and QRCodeValue.IsText() then
                    exit(QRCodeValue.AsValue().AsText());
            end;
        end;
    
        Error('QR code not found in middleware response JSON: %1', ResponseText);
    end;
     

    Key Points:


    • RequestContent.GetHeaders().Clear(): Ensures correct Content-Type by clearing defaults.

    • Two-step Error Checking: First for network issues (Client.Post return), then for middleware response status (Response.IsSuccessStatusCode).

    • Robust JSON Parsing: Added IsArray() and IsObject() checks for safer parsing.

    • Full Error Message: Display ResponseText on failure for middleware details.
     
    ✅ Mark this answer as verified if it helps 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,946 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,177 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 555 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans