web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • Hagru Profile Picture
    311 on at
    HttpClient.Get() returns FORBIDDEN when making call to SharePoint URL
    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.
  • Suggested answer
    YUN ZHU Profile Picture
    92,218 Super User 2025 Season 2 on at
    HttpClient.Get() returns FORBIDDEN when making call to SharePoint URL
    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
     
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,311 Super User 2025 Season 2 on at
    HttpClient.Get() returns FORBIDDEN when making call to SharePoint URL
    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

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 4,197

#2
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 3,673

#3
Sumit Singh Profile Picture

Sumit Singh 2,907

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans