Skip to main content

Notifications

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 230
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.
 
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    14,448 Super User 2025 Season 1 on at
    I have a problem Send (Base64EncodedXML) To the API.
     
  • Suggested answer
    Ramiz Profile Picture
    569 on at
    I have a problem Send (Base64EncodedXML) To the API.
    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;
     
  • gdrenteria Profile Picture
    17,492 Most Valuable Professional on at
    I have a problem Send (Base64EncodedXML) To the API.
  • Jainam M. Kothari Profile Picture
    5,891 on at
    I have a problem Send (Base64EncodedXML) To the API.
    Hello,
     
    May Other Technical Experts can answer it very well.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,095 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans