Attachments are not available immediately after subscription notification

Joshua Grippo 0 Reputation points
2023-11-14T15:11:10.4433333+00:00

After receiving a Subscription notification that an Email has been created. I check to see if the email has attachments. If it does, I attempt to download the attachments.
I will initially get the following exception:

Exception Type: Microsoft.Graph.ServiceException
Error: Code: ErrorItemNotFound
Message: The specified object was not found in the store., The store ID provided isn't an ID of an item.

If I repeatedly retry to download the attachments, it will eventually succeed after 4-5 minutes.

To Reproduce

  1. Get Message and Attachment List
    var msg = await graphClient.Me.Messages[MicrosoftId]
    .Request()
    .WithImmutableId()
    .Expand(EXPAND_MIME_HEADERS) .Select("internetMessageId,internetMessageHeaders,createdDateTime,subject,bodyPreview,hasAttachments,uniqueBody,body,from,toRecipients,ccRecipients,bccRecipients,isDraft")
    .GetAsync()
    .ConfigureAwait(false);

var atts = await graphClient.Me.Messages[MicrosoftId].Attachments
.Request()
.WithImmutableId()
.Select("id,name,size,isInline,contentType,microsoft.graph.fileAttachment/contentId")
.GetAsync(cancelAttachments.Token)
.ConfigureAwait(false);

foreach(var att in atts){
//Fails with above error
//failure is intermittent
var attMS = await graphClient.Me
.Messages[msg.Id]
.Attachments[att.Id]
.Request()
.WithImmutableId()
.GetAsync()
.ConfigureAwait(false) as FileAttachment;
}

I expect attachments to download.......

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,047 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.