-
Version: We want to check all file attachments of all messages of all mail folders of a specific user. Right now we do one API call per mail folder, one API call per message and one API call per attachments. For example, let's say we want to check the attachments of a specific mail folder of a specific user: resp, err := clientUsersById(userID).MailFoldersById(mailFolderID).Messages().Get(ctx, nil)
if err != nil {
// ...
}
messages := resp.GetValue() And now, we want to check attachments of every messages.
for _, message := range messages {
attachments := message.GetAttachments() // Empty
// ...
}
for _, message := range messages {
messageID := ...
resp, err := client.UsersById(userID).MailFoldersById(mailFolderID).MessagesById(messageID).Attachments().Get(ctx, nil)
if err != nil {
// ...
}
attachments := resp.GetValue()
// ...
} Are we doing it the best/optimal way by making one API call per object?
We need to do this for a specific user as fast as possible without hitting the API limit. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Thanks for reaching out and sorry about the late answer.
Here is an example on how to do that. graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestFilter := "hasAttachments eq true"
requestParameters := &graphconfig.ItemMessagesRequestBuilderGetQueryParameters{
Filter: &requestFilter,
Select: [] string {"id","hasAttachments"},
}
configuration := &graphconfig.ItemMessagesRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
}
result, err := graphClient.Me().Messages().Get(context.Background(), configuration) This repository and its discussions are dedicated to the SDK itself and is not monitored by the service team. To get answers from the service team, the best thing to do is to ask a question on the dedicated Microsoft Q&A forum |
Beta Was this translation helpful? Give feedback.
Thanks for reaching out and sorry about the late answer.
This is a limitation of the API today. You will have to iterate over mail folders and messages to get attachments, and as far as I'm aware, there are no bulk export APIs for this specific scenario.
You can optimize the scenario by:
Not only this will reduce the quota being used on the service side, but it'll also reduce the payload in transit.
Here is an example on how to do that.