REST API question : downloading attachments

%3CLINGO-SUB%20id%3D%22lingo-sub-1275160%22%20slang%3D%22en-US%22%3EREST%20API%20question%20%3A%20downloading%20attachments%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1275160%22%20slang%3D%22en-US%22%3E%3CP%3EIf%20I%20drag%20and%20drop%20an%20email%20%3CU%3Eattachment%3C%2FU%3E%20from%20a%20web%20outlook%20(that%20is%20from%20%3CA%20href%3D%22https%3A%2F%2Foutlook.office.com%2Fmail%2Finbox%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Foutlook.office.com%2Fmail%2Finbox%3C%2FA%3E%20open%20in%20a%20browser)%20%26nbsp%3Bto%20my%20desktop%20application%20I%20see%20the%20following%20JSON%20string%20in%20the%20drop%20event.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EattachmentV%7B%22itemType%22%3A%22attachment%22%2C%22attachmentFile%22%3A%7B%22attachmentItemId%22%3A%22AAMkADhmNz......%22%2C%22name%22%3A%22feb%20invoices%20archive.pdf%22%2C%22size%22%3A64276%2C%22fileType%22%3A5%2C%22type%22%3A%22ItemIdAttachment%3A%23Exchange%22%7D%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eso%20I%20have%20the%20attachmentItemId%20but%20no%20messageId%E2%80%A6.%20And%20yet%20the%20only%20endpoints%20I%20see%20for%20the%20rest%20API%20require%20a%20messageId.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ee.g.%20GET%20%3CA%20href%3D%22https%3A%2F%2Foutlook.office.com%2Fapi%2Fv2.0%2Fme%2Fmessages%2F%257bmessage_id%257d%2Fattachments%2F%257battachment_id%257d%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Foutlook.office.com%2Fapi%2Fv2.0%2Fme%2Fmessages%2F%7Bmessage_id%7D%2Fattachments%2F%7Battachment_id%7D%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20a%20way%20to%20download%20an%20attachment%20without%20knowing%20the%20message%20id%3F%20Or%20of%20finding%20the%20messageid%20that%20this%20attachment%20belongs%20to%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1275160%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1281626%22%20slang%3D%22en-US%22%3ERe%3A%20REST%20API%20question%20%3A%20downloading%20attachments%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1281626%22%20slang%3D%22en-US%22%3E%3CP%3Ebest%20i%20could%20find%20so%20far%20is%20to%20search%20messages%20for%20the%20file%20name%3C%2FP%3E%3CP%3E...%2Fmessages%2F%3F%24search%3D%22attachment%3A%7BName%7D%22%26amp%3B%24expand%3DAttachments%3C%2FP%3E%3CP%3Eand%20then%20loop%20through%20the%20returned%20messages%20and%20their%20attachments%20looking%20for%20the%20specific%20id.%3C%2FP%3E%3CP%3Enot%20ideal...%20but%20it's%20working.%3C%2FP%3E%3CP%3En.b.%20you%20have%20to%20replace%20any%20%22%2F%22%20characters%20with%20%22-%22%20and%20any%20%22%2B%22%20with%20%22_%22%20in%20the%20attachmentid%20when%20comparing%20with%20the%20id%20returned%20in%20the%20search.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

If I drag and drop an email attachment from a web outlook (that is from https://outlook.office.com/mail/inbox open in a browser)  to my desktop application I see the following JSON string in the drop event.

 

 

attachmentV{"itemType":"attachment","attachmentFile":{"attachmentItemId":"AAMkADhmNz......","name":"feb invoices archive.pdf","size":64276,"fileType":5,"type":"ItemIdAttachment:#Exchange"}}

 

 

so I have the attachmentItemId but no messageId…. And yet the only endpoints I see for the rest API require a 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? Or of finding the messageid that this attachment belongs to?

1 Reply
Highlighted

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.