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

Notifications

Announcements

Community site session details

Community site session details

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

HttpClient.Get() returns FORBIDDEN when making call to SharePoint URL

(1) ShareShare
ReportReport
Posted on by 337
Hello!
 
I have this small piece of code that is the beginning of a bigger procedure:
 

procedure ImportItemPictureFromURL()

    var

        Item: Record Item;

        Client: HttpClient;

        Content: HttpContent;

        Response: HttpResponseMessage;

        InStr: InStream;

    begin

        if PictureURL = '' then

            Error('Please enter a URL');

        Client.Get(PictureURL, Response);

        Response.Content.ReadAs(InStr);

        Item.SetRange("No.", ItemNo);

 
 
The procedure was made to upload images via a URL to items in Business Central, and it works really well.
However, I have encountered an issue, and that is the fact that all the images are stored in a SharePoint environment, and the URL's also reflect that.
When making a Client.Get() to the SharePoint URL, I get a 403 FORBIDDEN response, which is expected I suppose.
 
My question is - how can I modify my code to make sure I am authorized and can do a Client.Get() call to the URL and get the image in response?
 
I have the same question (0)
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,765 Super User 2026 Season 1 on at
    Hi,
     
    You must have the access token to authorize.
     
    How get the access token ? here you must read the MS documentation.
     
    BR,
    Mohamed Amine MAHMOUDI
  • Suggested answer
    YUN ZHU Profile Picture
    97,279 Super User 2026 Season 1 on at
    I recently tested some OneDrive examples and hope they can give you some tips.
    Dynamics 365 Business Central: How to use OAuth 2.0 in AL with SecretText (Using codeunit 501 OAuth2)
    Dynamics 365 Business Central: How to import/read files from OneDrive to Business Central via AL (Graph API)
    Dynamics 365 Business Central: How to upload files from Business Central to OneDrive via AL (Graph API)
     
    Thanks.
    ZHU
     
  • Hagru Profile Picture
    337 on at
    I have already set up an app in Azure in order to make API calls from Postman, I think similar to how Yun Zhu did in the first link he posted. I tried using the same authorization in Postman with a valid token, but got the "401 UNAUTHORIZED" in response. 
     
    Is there something specific I need to do to give it access to the SharePoint as well?
     
    Once I have the authorization down, I am sure I can modify the code in a similar way Yun Zhu did to send the token with the call.

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…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,170 Super User 2026 Season 1

#2
Dhiren Nagar Profile Picture

Dhiren Nagar 1,283 Super User 2026 Season 1

#3
YUN ZHU Profile Picture

YUN ZHU 1,104 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans