Search code examples
office365apioutlook-restapioffice365-restapi

Retrieving mail items with Id and Outlook REST API


Given a list of Ids (aka ItemIds) how can we efficiently retrieve the emails with OutlookREST Api?

I tried to forge the following request.

https://outlook.office365.com/api/beta/me/MailFolders/<somefolderId>/messages?$filter=((Id eq 'firstId') or (Id eq 'secondId') or (Id eq 'thirdId'))

But I received a BadRequest 400 error: "The property 'Id' does not support filtering" which is very clear.

As a workaround I use the InternetMessageId (I do not care which "copy" of the email is returned). Is there a way to use the Id to achieve better performance ?


Solution

  • You could do up to 20 individual GET requests for each ID in a batch request. This is only available on the beta endpoint right now.

    Something like:

    POST https://outlook.office.com/api/beta/$batch HTTP/1.1
    
    Authorization: Bearer aGFwcHlnQGRr==
    Host: outlook.office.com
    Content-Type: multipart/mixed; boundary=batch_myBatchId
    
    
    --batch_myBatchId
    Content-Type: application/http
    Content-Transfer-Encoding: binary
    
    GET  /api/beta/me/messages/{id1}    HTTP/1.1
    
    
    --batch_myBatchId
    Content-Type: application/http
    Content-Transfer-Encoding: binary
    
    GET  /api/beta/me/messages/{id2}    HTTP/1.1
    
    
    --batch_myBatchId--