Microsoft Graph Api - upload file and invalidRequest

tymon130 1 Reputation point
2022-09-27T12:04:28.827+00:00

Hi,
I have a problem uploading files to sharepoint using the graph api.
With the token downloaded from https://developer.microsoft.com/en-us/graph/graph-explorer everything works fine. I get a response with a status of 200.
245142-1.png

However, when I want to upload a file with a token received from AD I get an invalid request.
245068-3.png
In the scope of my token there is: "Files.ReadWrite Files.ReadWrite.All Group.Read.All Group.ReadWrite.All GroupMember.Read.All GroupMember.ReadWrite.All openid profile Sites.Read.All Sites.ReadWrite.All User.Read email".

Reading the file list works without any problems

Below is the code on how I generate the token to Graph Api
245126-image.png

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,592 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,668 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Tong Zhang_MSFT 9,116 Reputation points
    2022-09-28T06:50:18.48+00:00

    Hi @tymon130 ,

    According to my research and testing, you can use the following API to generate the access_token to Graph API, and then upload file:

    https://login.microsoftonline.com/tenant-id/oauth2/token  
    

    245385-01.png

    Then, you can use the access_token , and upload file to SharePoint, here is my test result:

    245414-02.png

    More information for reference: https://dzone.com/articles/getting-access-token-for-microsoft-graph-using-oau

    Hope it can help you. Thanks for your understanding.

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



  2. tymon130 1 Reputation point
    2022-10-02T06:34:50.8+00:00

    My case involves uploading files on behalf of a user. The way you have shown is through the application. Unfortunately I don't get such permissions.

    0 comments No comments