Unable to get file drive item via /shares/{encoded_webUrl} after listing children

Oleksandr 20 Reputation points
2024-08-05T07:43:20.8166667+00:00

I encountered an issue when getting a drive item via /shares endpoint. After listing drive items via /me/drive/root/children and using encoded webUrl in /shares endpoint (as described here ) graph api returns "invalidRequest: Invalid shares key." error. After some investigation I found that webUrl of drive items changed about 2-3 weeks ago. Before, listing drive items (like .xlsx files) would return webUrl similar to: https://onedrive.live.com/personal/946c98d07c563ce7/_layouts/15/doc.aspx?resid=946C98D07C563CE7!381&cid=946c98d07c563ce7

Now, however, webUrl looks similar to: https://onedrive.live.com/personal/946c98d07c563ce7/_layouts/15/doc.aspx?resid=7c563ce7-98d0-206c-8094-7d0100000000&cid=946c98d07c563ce7

So only resid is different, and after encoding current webUrl and using it in /shares endpoint graph api returns an error. I tested this with Postman. To access graph api I am using OAuth2.0 access token with "Files.ReadWrite offline_access" scopes. I am unable to find any change logs regarding this change, so is there some changes I need to make to my Entra application that I am using in OAuth2.0 flow to return webUrl as it was before? If not, how can I use the new webUrl in the /shares endpoint without manually editing it? It is vital for me to use /shares endpoint.
Thank you.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,828 questions
OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
1,072 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,938 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yakun Huang-MSFT 4,160 Reputation points Microsoft Vendor
    2024-08-06T07:09:46.17+00:00

    Hi @Oleksandr

    For this problem, you can try the following two approaches.

    According to the documentation, you need to first create a shared link for the DriveItem that you want to share, and then encode that link.

    When you create a shared link, shareId is also returned, and according to the documentation, you can also use shareId for access.

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.