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...
Answered

HTTP GET Authorization problem

(0) ShareShare
ReportReport
Posted on by 67

Hello!

I have a problem with a GET query.

POST queries work without any problem while GET has an authorization error. My code:

procedure GetProductInfo(_ItemId: Integer; _Token: Text)
var
    Client: HttpClient;
    Request: HttpRequestMessage;
    Response: HttpResponseMessage;
    Headers: HttpHeaders;
    Uri: Text;
    FullToken: Text;
    ResponseTxt: Text;
    Json: JsonObject;
begin
    Uri := 'https://myaddress.com/product/'   Format(_ItemId);
    FullToken := 'Bearer '   Format(_Token);

    Request.Method := 'GET';
    Request.SetRequestUri(Uri);
    Headers.Add('Authorization', FullToken);
    Request.GetHeaders(Headers);
    Client.Send(Request, Response);

    if Response.IsSuccessStatusCode() then begin
        Response.Content.ReadAs(ResponseTxt);
        Json.ReadFrom(ResponseTxt);

        ProductId := GetJsonTextField(Json, 'product_id');
        ProductCode := GetJsonTextField(Json, 'code');
        Evaluate(Stock, GetJsonTextField(Json, 'stock'));

        Message('Good');
    end
    else
        Message('Bad');
end;

Error: HTTP 401

Everything works fine in Postman.

Best Regards

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Hi,

    Please try this

           http_Content.GetHeaders(http_Header);

           http_Header.Clear();

           http_Client.DefaultRequestHeaders.Add('Authorization', 'Bearer ' + APIKey + '');

           http_Header.Add('Content-Type', 'application/json');

           if http_Client.get(APIURL, httpResMsg) then

  • Alzack18 Profile Picture
    67 on at

    Thank you for response! I changed

    Headers.Add('Authorization', FullToken);

    to

    Client.DefaultRequestHeaders.Add('Authorization', FullToken);

    Problem solved!

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Great.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 795 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 561 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 323 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans