C.E James
C.E James

Reputation: 335

Merge queries using Microsoft Graph API

I am new to Microsoft Graph API. The requirement on our application is to collect the latest email based on expected subject and collect the attachment of the email (CSV format).

This is working fine already when using the queries below but using 2 GET requests:

First is for collecting the latest email:

https://graph.microsoft.com/v1.0/me/messages?$select=id,hasAttachments&$top=1&$filter=subject eq '{subject}'

Second is for collecting the attachment by passing the id returned from the first query:

https://graph.microsoft.com/v1.0/me/messages/{id}/attachments

Question: Is there a way to just merge this request into one to make the code even better?

Thank you!

Upvotes: 0

Views: 668

Answers (2)

C.E James
C.E James

Reputation: 335

Update: I was able to merge two requests with the user of $expand parameter:

https://graph.microsoft.com/v1.0/me/messages?$select=id,hasAttachments&$top=1&$filter=subject eq '{subject}'&$expand=attachments

Upvotes: 1

Diana
Diana

Reputation: 718

To my current knowledge, there isn't a way to merge these two requests. As you have pointed out, the message id is required to list attachments.

Upvotes: 0

Related Questions