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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

I have a problem Send (Base64EncodedXML) To the API.

(4) ShareShare
ReportReport
Posted on by 322
I want help from experienced people.......
 
Al code is attached in a file named "Sale Invoice Ext." in the attachments.
 
I have a problem receiving responses from the API. I specifically receive a QR code, store it in the system, and then print it on the sales invoice as requested. The system sends the invoice data, but gives me an error when executing (Failed to call the API. Error: Error code: 85132273). When I try it on Postman, it gives me a valid response and the barcode was sent successfully. The problem I have now is that when sending from within the Business Central  , it gives me the following error:
 
Base64EncodedXML: PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48SW52b2ljZSB4bWxucz0idXJuOm9hc2lzOm5hbWVzOnNwZWNpZmljYXRpb246dWJsOnNjaGVtYTp4c2Q6SW52b2ljZS0yIiB4bWxuczpjYmM9InVybjpvYXNpczpuYW1lczpzcGVjaWZpY2F0aW9uOnVibDpzY2hlbWE6eHNkOkNvbW1vbkJhc2ljQ29tcG9uZW50cy0yIiB4bWxuczpleHQ9InVybjpvYXNpczpuYW1lczpzcGVjaWZpY2F0aW9uOnVibDpzY2hlbWE6eHNkOkNvbW1vbkV4dGVuc2lvbkNvbXBvbmVudHMtMiIgeG1sbnM6Y2FjPSJ1cm46b2FzaXM6bmFtZXM6c3BlY2lmaWNhdGlvbjp1Ymw6c2NoZW1hOnhzZDpDb21tb25BZ2dyZWdhdGVDb21wb25lbnRzLTIiPjxjYmM6UHJvZmlsZUlEPnJlcG9ydGluZzoxLjA8L2NiYzpQcm9maWxlSUQ+PGNiYzpJRD5QU0kvMjUvMDAxMjc8L2NiYzpJRD48Y2JjOlVVSUQ+UFNJLzI1LzAwMTI3LTEyMzwvY..............
 
PostMan :
 
I want the correct way to send
 
===============================================================================================================================================
This is part of the  AL code " 
 
procedure SendInvoiceToAPI(EncodedXML: Text; ClientId: Text; SecretKey: Text): Text
    var
        HttpClient: HttpClient;
        HttpRequestMessage: HttpRequestMessage;
        HttpResponseMessage: HttpResponseMessage;
        RequestContent: HttpContent;
        ResponseText: Text;
        JsonBody: Text;
        ContentHeaders: HttpHeaders;
        RequestHeaders: HttpHeaders;
    begin
        // JSON body
        JsonBody := '{"invoice": "' + EncodedXML + '"}';
        RequestContent.WriteFrom(JsonBody);
 
        
        RequestContent.GetHeaders(ContentHeaders);
        ContentHeaders.Remove('Content-Type')
        ContentHeaders.Add('Content-Type', 'application/json');
 
        
        HttpRequestMessage.Method := 'POST';
        HttpRequestMessage.SetRequestUri('https://backend.jofotara.gov.jo/core/invoices/');
        HttpRequestMessage.Content := RequestContent;
 
       
        HttpRequestMessage.GetHeaders(RequestHeaders);
        RequestHeaders.Add('Client-Id', ClientId);
        RequestHeaders.Add('Secret-Key', SecretKey);
 
        
        if not HttpClient.Send(HttpRequestMessage, HttpResponseMessage) then begin
            SaveBarcodeValue(Rec."No.", 'Error');
            Error('Failed to call the API. Error: %1', GetLastErrorText());
        end;
 
        
        if not HttpResponseMessage.Content.ReadAs(ResponseText) then begin
            SaveBarcodeValue(Rec."No.", 'Error');
            Error('Failed to read API response.');
        end;
 
        
        if not HttpResponseMessage.IsSuccessStatusCode then begin
            SaveBarcodeValue(Rec."No.", 'Error');
            Error('API request failed with status code: %1. Response: %2', HttpResponseMessage.HttpStatusCode, ResponseText);
        end;
 
        exit(ResponseText);
    end;
===============================================================================================================================================
 
Al code is attached in a file named "Sale Invoice Ext." in the attachments.
 
I have the same question (0)
  • Jainam M. Kothari Profile Picture
    15,639 Super User 2025 Season 2 on at
    Hello,
     
    May Other Technical Experts can answer it very well.
  • Gerardo Rentería García Profile Picture
    25,371 Most Valuable Professional on at
  • Suggested answer
    Ramiz Profile Picture
    597 on at
    Hi,

    Print the response error message and see if you see the problem in the response
     
            if not HttpClient.Send(HttpRequestMessage, HttpResponseMessage) then begin
                SaveBarcodeValue(Rec."No.", 'Error');
                HttpResponseMessage.Content.ReadAs(ResponseText)
                Error('Failed to call the API. Error: %1', ResponseText);
            end;
     
     
     
    lHttpRequestMessage.SetRequestUri(pUrl);
    lHttpRequestMessage.Method := pMethod;
    lHttpContent.WriteFrom(pPayload);
    lHttpContent.GetHeaders(lHttpContentHeaders);
    lHttpContentHeaders.Remove('Content-Type');
    lHttpContentHeaders.Add('Content-Type', 'application/json');
    lHttpRequestMessage.Content := lHttpContent;
    lHttpRequestMessage.GetHeaders(lHttpHeaders);
    lHttpHeaders.Add('clientid', pClientID);
    lHttpHeaders.Add('clientsecret', pClientSecretID);
    if not lHttpClient.Send(lHttpRequestMessage, lHttpResponseMessage) then beign
    	lHttpResponseMessage.Content.ReadAs(ResponseText)
    	Error(ResponseText);
    end;
     
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    20,643 Super User 2025 Season 2 on at

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,066

#2
YUN ZHU Profile Picture

YUN ZHU 658 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 595

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans