API Mailbox Item Import

Jan Berlinger - credaris.ch 0 Reputation points
2025-11-24T16:04:37.9766667+00:00

Hi there

We would like to create an Exchange import session to prepare an import of an EML file to Outlook.

POST https://graph.microsoft.com/beta/admin/exchange/mailboxes/******@domain.com/createImportSession

API documented here: https://v4.hkg1.meaqua.org/en-us/graph/import-exchange-mailbox-item.

We use the application permission MailboxItem.ImportExport.All in the App Registration (with admin grant).

The session gets successfully established and as a respones we get the ImportUrl:
https://outlook.office365.com/api/gbeta/Mailboxes('MBX:<ID>')/importItem?authtoken=<token>

Still, when we use the ImportUrl to upload the file, we receive an 403 Forbidden response.

JSON Body:

{
"FolderId":"<FolderId>",
"Mode":"create",
"Data":"<Base64Payload>"
}

In the response header we see the following header:

WWW-Authenticate: Bearer client_id="<clientId>", trusted_issuers="<issuerId@*", token_types="app_asserted_user_v1 service_asserted_app_v1", error="invalid_token"

As the request is preauthenticated I would not expect this error at all.

Do you know if we need to fulfill additional pre-requisites to successfully import the document?

Thanks,

Exchange Online
Exchange Online
A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Q&A Assist
    2025-11-24T16:04:48.66+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    It sounds like you are encountering a 403 Forbidden error when trying to upload the item using the ImportUrl after successfully creating the import session. This error typically indicates that there are issues with the authentication token or permissions.

    Here are a few things you can check:

    1. Token Validity: Ensure that the token you are using in the ImportUrl is still valid and has not expired. The expirationDateTime property in the mailboxItemImportSession response indicates how long the token is valid.
    2. Permissions: Double-check that the application permission MailboxItem.ImportExport.All is correctly granted and that the user or service principal making the request has the necessary permissions to perform the import operation.
    3. Correct FolderId: Make sure that the FolderId you are providing in the JSON body is valid and that the user has access to that folder.
    4. Base64 Encoding: Verify that the data you are sending in the Data field is correctly base64 encoded and represents a valid EML file.

    If all of these checks are correct and you are still facing issues, you may want to review the API documentation for any additional requirements or reach out to Microsoft support for further assistance.


    References:

    0 comments No comments

  2. Vergil-V 7,550 Reputation points Microsoft External Staff Moderator
    2025-11-25T02:23:10.5+00:00

    Hi @Jan Berlinger - credaris.ch 
    Thanks for reaching out to the Microsoft Q&A forum. I appreciate the details you shared along with the documentation link. 

     After reviewing the article you provided and your description, I noticed that the data used in step 2, "Use the import URL to upload an item", is expected to be in Base64-encoded FTS format. 

    User's image Regarding the 403 Forbidden responses with Data: "<Base64Payload>", may I confirm whether this payload is a Base64-encoded EML file?

    Additionally, please note that an Exchange mailbox item needs to be exported first before it can be imported into another folder. This ensures the item data is in the correct Base64-encoded FTS format. 

    undefined For importing an EML file, Microsoft Graph supports scenarios where EML can be imported as a MIME format draft message. You can refer to this example: 

    undefined Reference: Create message - Microsoft Graph v1.0 | Microsoft Learn 

    If you want to use mailbox import and export APIs for EML files, you can import the EML file into Outlook either by using the above API to create a draft message or by importing it directly into any folder through the New Outlook desktop version. 

    undefined

    Once the items are imported, you can export them using exportItems. After you have the correct data format, try reproducing the steps to check if the issue persists. 

     

    I sincerely hope this information helps clarify your situation and supports you in resolving the issue. Please don’t hesitate to reply if you have any updates. 

    Thank you for your understanding. 


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


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.