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.