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

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

(1) ShareShare
ReportReport
Posted on by 311
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,423 Super User 2025 Season 2 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
    95,718 Super User 2025 Season 2 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
    311 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…

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 2,664

#2
YUN ZHU Profile Picture

YUN ZHU 960 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 773 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans