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 for those with experience with the subject of sending to API

(4) ShareShare
ReportReport
Posted on by 322
Hi For All
 
I have the following code, this code works perfectly in another project but on this project that I am currently working on it does not work and when I execute it gives me the following error "Failed to call the API." Very strange, I tried to trace the error but no details of the error appeared.
 
The problem is definitely not with the code because it works for me in another project and the same environment version as well... Are there other reasons? Is there anything preventing the code from connecting to "API" directly?
 
The user's permissions are full super, and I entered the "Azure Portal" website and gave all permissions, but to no avail.
 
 
Please help, thank you very much
 
  procedure SendInvoiceToAPI(EncodedXML: Text; ClientId: Text; SecretKey: Text): Text
    var
        HttpClient: HttpClient;
        HttpRequestMessage: HttpRequestMessage;
        HttpResponseMessage: HttpResponseMessage;
        RequestContent: HttpContent;
        ResponseText: Text;
        JsonBody: Text;
        HttpHeaders: HttpHeaders;
    begin
        // إعداد JSON body
        JsonBody := '{"invoice": "' + EncodedXML + '"}';
        RequestContent.WriteFrom(JsonBody);
 
        // إعداد رؤوس الطلب
        RequestContent.GetHeaders(HttpHeaders);
        HttpHeaders.Clear();
        HttpHeaders.Add('Content-Type', 'application/json');
        HttpHeaders.Add('Client-Id', ClientId)
        HttpHeaders.Add('Secret-Key', SecretKey)
 
        // إرسال الطلب
        HttpRequestMessage.SetRequestUri('https://backend.jofotara.gov.jo/core/invoices/');
        HttpRequestMessage.Method := 'POST';
        HttpRequestMessage.Content := RequestContent;
 
        if not HttpClient.Send(HttpRequestMessage, HttpResponseMessage) then begin
            SaveBarcodeValue(Rec."No.", 'Error');
            Error('Failed to call the API.');
        end;
 
        // قراءة الاستجابة
        HttpResponseMessage.Content.ReadAs(ResponseText);
 
        // التحقق من استجابة API
        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;
I have the same question (0)
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    20,363 Super User 2025 Season 2 on at
    Have you set microsoft entra Application?  and have you checked it on postman?
     
  • Suggested answer
    Jainam M. Kothari Profile Picture
    15,631 Super User 2025 Season 2 on at
  • Vahid Ghafarpour Profile Picture
    12,090 Super User 2025 Season 2 on at
    If any of the responses helped resolve your issue, please take a moment to mark the best answer. This helps others in the community quickly find solutions to similar problems.

    To do this, simply click the "Does this answer your question?" button on the most helpful response and like the helpful posts. If your issue is still unresolved, feel free to provide more details so the community can assist further!

    Thanks for being an active part of the Dynamics 365 Community! 😊

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 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans