Graph API call fails when trying to get message using mailbox address and mailbox item id

Diluka Hewage 96 Reputation points
2023-06-30T09:42:22.4666667+00:00

I have developed an outlook add-in. Following I have provided two Graph API calls that I have performed to get the content of the two messages.

/v1.0/users/{upn}/messages/AAMkADdhMjY3ZGZlLTdkMDEtNGY2My05MGZjLTA4ZDg5ZmFlZTkzYwBGAAAAAAAjGPAq_ky9Sa2u5PJCXKvrBwBxcgnfxEocT4t2yPsoE0AOAAAAAAEMAABxcgnfxEocT4t2yPsoE0AOAABpZimQAAA=

 
/v1.0/users/{upn}/messages/AAMkAGJhYzI3YjhkLWM0ZTgtNDIyOS1iY2MyLWE0ZTVlMTdhMDJmZQBGAAAAAAAjGPAq_ky9Sa2u5PJCXKvrBwBxcgnfxEocT4t2yPsoE0AOAAAAAAEMAABxcgnfxEocT4t2yPsoE0AOAABpZimQAAA=

First API call has successfully executed and I got the message. But the second API call was failed and provided following error.

{

    "error": {

        "code": "ErrorInvalidMailboxItemId",

        "message": "Item 'AAMkAGJhYzI3YjhkLWM0ZTgtNDIyOS1iY2MyLWE0ZTVlMTdhMDJmZQBGAAAAAAAjGPAq_ky9Sa2u5PJCXKvrBwBxcgnfxEocT4t2yPsoE0AOAAAAAAEMAABxcgnfxEocT4t2yPsoE0AOAABpZimQAAA=' doesn't belong to the targeted mailbox 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.",

        "innerError": {

            "date": "2023-06-30T07:35:52",

            "request-id": "065d6d9e-7980-4156-895f-253430032a17",

            "client-request-id": "07a35c14-98cf-ce87-6e62-3866f066779b"

        }

    }

}

I got the mail item ids using following command by using office.js.

Office.context.mailbox.item.itemId

NOTE : Both messages are physically available in Outlook desktop

Can anyone help with this issue?

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Diluka Hewage 96 Reputation points
    2023-06-30T10:24:50.0766667+00:00

    Hello Priscilla,
    Thank you so much for your answer.

    I have ensured that the {upn} parameter in the API URL is set to the correct user principal name, my application has the necessary scopes and permissions to access the mailbox and read messages and also item ids are all correct.

    Messages are also placed in one after the other in the same mailbox. The issue is first API call was successful and second one is unsuccessful.

    1 person found this answer helpful.
    0 comments No comments

  2. Priscilla Soares | Escola São Domingos 405 Reputation points
    2023-06-30T10:03:39.8733333+00:00

    Hello Diluka,

    The error message you received indicates that the second API call failed with the error "ErrorInvalidMailboxItemId". The error message suggests that the item ID provided in the API call does not belong to the targeted mailbox.

    Here are a few suggestions to troubleshoot the issue:

    Verify the Targeted Mailbox: Ensure that the {upn} parameter in the API URL is set to the correct user principal name (UPN) or mailbox identifier. Double-check that the targeted mailbox is the one where the desired email is located.

    Confirm Proper Scopes and Permissions: Make sure that your application has the necessary scopes and permissions to access the mailbox and read messages. Check that the access token used for the API calls contains the required permissions for retrieving the messages.

    Check Message Accessibility: Confirm that the messages you are trying to access are visible and accessible in the targeted mailbox. Ensure that the messages haven't been moved or deleted. It's possible that the message you are trying to retrieve using the second API call is not present in the specified mailbox.

    Validate Item ID: Review the item IDs you obtained using the Office.context.mailbox.item.itemId in your Outlook add-in. Double-check that the item ID used in the second API call is correct and corresponds to the desired email message. Ensure that the item ID hasn't been modified or corrupted between obtaining it from the add-in and using it in the API call.

    By reviewing these points, you can identify any potential issues that may be causing the "ErrorInvalidMailboxItemId" error. Double-checking the mailbox, permissions, message accessibility, and item ID will help ensure the correctness of the API call and increase the chances of successful retrieval of the desired email message.

    0 comments No comments

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.