Download Item Attchment using Graph client API

Natrix De 1 Reputation point
2020-10-30T18:25:33.933+00:00

How Can I download item attachment using graph client API in my .NET core app?

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

2 answers

Sort by: Most helpful
  1. Vasil Michev 103.7K Reputation points MVP
    2020-10-30T20:02:39.563+00:00

    Are you looking for a ready to use code or? Generally speaking, you use the /messages/{item-id}/attachments/{attach-id}/$value endpoint, as detailed here: https://learn.microsoft.com/en-us/graph/api/attachment-get?view=graph-rest-1.0&tabs=http


  2. Deva-MSFT 2,266 Reputation points Microsoft Employee
    2020-10-31T20:01:25.957+00:00

    With MS Graph Explorer i would try like this:

    https://graph.microsoft.com/v1.0/me/messages/AAMkAGRlNWM4Njk4LWY3NTYtNGE2MC05ZjQzLTg1YmM5YjIzNTRhMwBGAAAAAAA-L78mmzKFQ7FpvCcWkAziBwCUgufVfU8cSKxkYzIkrl81AAAAAAEMAACUgufVfU8cSKxkYzIkrl81AACPpiPUAAA=/attachments/AAMkAGRlNWM4Njk4LWY3NTYtNGE2MC05ZjQzLTg1YmM5YjIzNTRhMwBGAAAAAAA-L78mmzKFQ7FpvCcWkAziBwCUgufVfU8cSKxkYzIkrl81AAAAAAEMAACUgufVfU8cSKxkYzIkrl81AACPpiPUAAABEgAQAHuvC2KF7iBGiNpH9HGIZ8k=/  
      
    

    If it's GraphClient i would try like this (adding the code sample):

    GraphServiceClient graphClient = new GraphServiceClient( authProvider );  
      
    var attachment = await graphClient.Me.Messages["AAMkAGRlNWM4Njk4LWY3NTYtNGE2MC05ZjQzLTg1YmM5YjIzNTRhMwBGAAAAAAA-L78mmzKFQ7FpvCcWkAziBwCUgufVfU8cSKxkYzIkrl81AAAAAAEMAACUgufVfU8cSKxkYzIkrl81AACPpiPUAAA="].Attachments["AAMkAGRlNWM4Njk4LWY3NTYtNGE2MC05ZjQzLTg1YmM5YjIzNTRhMwBGAAAAAAA-L78mmzKFQ7FpvCcWkAziBwCUgufVfU8cSKxkYzIkrl81AAAAAAEMAACUgufVfU8cSKxkYzIkrl81AACPpiPUAAABEgAQAHuvC2KF7iBGiNpH9HGIZ8k="]  
    	.Request()  
    	.GetAsync();  
    

    Result:
    This will get me the content byte from the item attachment (adding a snapshot):

    36564-resultoutput.jpg

    Hope this helps.


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.