Reputation: 89
Drag and dropping a file from a browser logged into office365/outlook
gives me a JSON string with the attachmentItemId but not the message ID.
attachmentV{"itemType":"attachment","attachmentFile":{"attachmentItemId":"AAMkADhmNz......","name":"feb invoices archive.pdf","size":64276,"fileType":5,"type":"ItemIdAttachment:#Exchange"}}
Yet the only endpoints I can see for fetching an attachment require the messageID.
e.g. GET https://outlook.office.com/api/v2.0/me/messages/{message_id}/attachments/{attachment_id}
Is there a way to download an attachment without knowing the message id?
Upvotes: 0
Views: 378
Reputation: 478
I found a way to get the messageId based on the attachmentItemId.
It seems that if you make this call:
HTTP GET GET https://graph.microsoft.com/v1.0/me/messages/{attachmentItemId}
You get the same response as if you would have made this call:
HTTP GET GET https://graph.microsoft.com/v1.0/me/messages/{messageId}
And that response is a JSON object that has an id property, which will be the message id.
So once you have that, you can just do this call:
HTTP GET https://graph.microsoft.com/v1.0/me/messages/{message_id}/attachments/{attachment_id}
You would expect that if you use that last call with twice the attachment-id parameter it should also work, but no. I have no idea where this would be documented, or how they expect you to figure this out... But I guess it is a bit better then searching for all attachments by name
PS: I assume that my solution that calls the graph api with a user token will work the same way as the outlook.office.com api that was used in the question. But I have not tested it.
Upvotes: 0
Reputation: 89
best i could find so far is to search messages for the file name
.../messages/?$search="attachment:{Name}"&$expand=Attachments
and then loop through the returned messages and their attachments looking for the specific id.
not ideal... but it's working.
n.b. you have to replace any "/" characters with "-" and any "+" with "_" in the attachmentid when comparing with the id returned in the search.
Upvotes: 0