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...
Suggested Answer

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

(1) ShareShare
ReportReport
Posted on by 339
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,779 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
    98,060 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
    339 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

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,091 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,032 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 946 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans