Downloading Forwarded Attachments From Teams Chat via Microsoft Graph API

Mustafa Salihi 0 Reputation points
2025-03-07T09:30:36.94+00:00

I am trying to download a forwarded attachment using Microsoft Graph API. The scenario is as follows:

Person A sends an attachment to Person B. Person B then forwards the attachment to me. When I attempt to download the attachment using the following Graph API request: GET /shares/{shareIdOrUrl}/driveItem 'https://learn.microsoft.com/en-us/graph/api/shares-get'

I receive the following error:

{

"code": "invalidRequest",

"message": "Share URL does not point to a drive item or no permission to access it."

}

However, if either Person A or Person B grants me access via the Teams app, I can successfully retrieve the downloadUrl and no longer encounter this error.

Is there an API that I can invoke to programmatically grant access so that I can retrieve the downloadUrl without requiring manual intervention?

Any guidance or alternative approaches would be greatly appreciated.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,276 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Saranya Madhu-MSFT 1,895 Reputation points Microsoft External Staff
    2025-03-11T04:28:10.1266667+00:00

    Hi Mustafa Salihi,

    As per Microsoft documentation, you can grant users access to a link represented by a permission using the following API:

    POST https://graph.microsoft.com/v1.0/shares/{encoded-sharing-url}/permission/grant
    Content-type: application/json
     
    {
      "recipients": [
        {
          "email": ******@contoso.com
        },
        {
          "email": ******@external.com
        }
      ],
      "roles": ["read"]
    }
     
    

    This API allows you to specify the recipients and the roles (e.g., "read") to grant access to the shared link. The action to grant access to the shared file should be performed by the owner of the file or someone who already has the necessary permissions to manage access to the file. This ensures that the correct permissions are set and that the file is securely shared with the intended recipients.

    Additional reference: List permissions

    Hope this helps.

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

    0 comments No comments

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.