Share via

failing to fetch email MIME content for itemId using Graph

Vikram Kaparthi (external) 0 Reputation points
2026-04-30T13:35:59.4466667+00:00

Hi Team,
We migrated from EWS to Graph to fetch email content, but for one of our user the MS Graph is throwing
400 Bad Request with error as
{"error":{"code":"ErrorInvalidIdMalformed","message":"Id is malformed."}}
GraphUrl : https://graph.microsoft.com/v1.0/users/{user}/messages/{id}/$value
Note : here user refers to user email id and
id as itemId( encoded using URLEncoder.encode(itemId, StandardCharsets.UTF_8) )

Microsoft Security | Microsoft Graph
0 comments No comments

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2026-04-30T13:36:16.2533333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The ErrorInvalidIdMalformed response indicates that the {id} segment in the URL is not in the format Microsoft Graph expects for a message ID.

    Key points from the context:

    1. To get the MIME content of a message, the supported pattern is:
         GET /users/{id}/messages/{id}/$value
      
      or for the signed-in user:
         GET https://graph.microsoft.com/v1.0/me/messages/{message-id}/$value
      
      The {message-id} here must be the Graph message ID returned by Microsoft Graph (for example from a prior GET /messages or POST /messages), not the EWS ItemId or another legacy identifier.
    2. When migrating from EWS to Graph, using the old EWS ItemId directly as the {id} path parameter will cause ErrorInvalidIdMalformed, because Graph cannot parse that ID as a valid Graph message ID.
    3. The context also notes that the MIME content is returned when $value is appended and the response starts with the MIME-Version header, confirming that the call pattern itself is correct once a valid Graph message ID is used.

    Given this, the issue is most likely:

    • The itemId being URL-encoded and used in the path is not a Graph message ID.
    • URL-encoding alone (for example via URLEncoder.encode(itemId, StandardCharsets.UTF_8)) does not convert an EWS ID into a Graph ID; it only makes it safe for use in a URL.

    To resolve:

    1. Ensure that the {id} in /users/{user}/messages/{id}/$value is the actual id property returned by Microsoft Graph for that message.
    2. If only an EWS ItemId is available, first locate the corresponding message in Graph (for example by querying on other properties such as subject, sent/received time, or internet message ID) and then use the Graph id from that result in the $value call.
    3. Keep URL encoding limited to making the Graph id path-safe; do not attempt to reuse or transform EWS IDs as Graph IDs.

    References:

Your answer

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