Graph API calls for on-prem mailboxes failing with API Status code 400 AuthenticationError

Rono, Jacob 21 Reputation points
2023-05-31T13:35:46.7033333+00:00

We are using the below Graph API request to list mail folders from a mailbox in a hybrid deployment tenant.

https://graph.microsoft.com/v1.0/users/mailid/MailFolders/?$top=500

We are seeing we are getting sometimes API HttpError with Status Code 400 and sometimes API HttpError with Status Code 404 for the same mailbox

API HttpError 400 when requesting https://graph.microsoft.com/v1.0/users/[mailid]/MailFolders/?$top=500
Response:{u'error': {u'innerError': {u'date': u'2023-05-26T07:41:43', u'request-id': u'xxxxxxxxxxxxxxxxx', u'client-request-id': u'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'}, u'message': u'Error authenticating with resource', u'code': u'AuthenticationError'}}'

API HttpError 404 when requesting https://graph.microsoft.com/v1.0/users/[mailid]/MailFolders/?$top=500 _
Response:{u'error': {u'innerError': {u'date': u'2023-05-31T11:48:23', u'request-id': u'xxxxxxxxxxxx', u'client-request-id': u'xxxxxxxxxxxxxxxxx'}, u'message': u'The mailbox is either inactive, soft-deleted, or is hosted on-premise.', u'code': u'MailboxNotEnabledForRESTAPI'}}_

Can someone help why we are getting different responses every time? and what does API Status Code 400 and API Status Code 400 and 'message': u'Error authenticating with resource', u'code': u'AuthenticationError' signifies?

Microsoft Exchange Online
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,581 questions
Microsoft Exchange Hybrid Management
Microsoft Exchange Hybrid Management
Microsoft Exchange: Microsoft messaging and collaboration software.Hybrid Management: Organizing, handling, directing or controlling hybrid deployments.
1,886 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. TH-4749-MSFT 3,290 Reputation points
    2023-05-31T20:44:50.6433333+00:00

    Hello Rono, Jacob,

    Thanks for reaching out. The ability to use these REST APIs in hybrid deployments will no longer be available and begin to return errors for any requests made for mailboxes that remain on-premises. Please see articles https://learn.microsoft.com/en-us/graph/hybrid-rest-support and https://techcommunity.microsoft.com/t5/exchange-team-blog/the-end-of-the-rest-api-for-on-premises-mailboxes-preview/ba-p/3221219 for more information.

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

    Thanks.


  2. TH-4749-MSFT 3,290 Reputation points
    2023-06-02T15:45:15.7733333+00:00

    Hello Rono, Jacob,

    Thanks for your response. Currently there is no Graph API to identify if the mailbox is hosted on Prem. The Beta version of the users/[userid] endpoint returns some on-Prem attributes including custom attributes that you could leverage, for example add a custom attribute to accounts with on-prem mailboxes and then filter using that attribute. Note however that it is not recommended to use beta version of the API for production.

    Regarding if there is a way via EWS you can post your query in the Exchange community forum

    https://techcommunity.microsoft.com/t5/exchange/ct-p/Exchange.

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

    Thanks.

    0 comments No comments

  3. TH-4749-MSFT 3,290 Reputation points
    2023-06-09T14:20:30.3933333+00:00

    Hello Rono, Jacob,

    Good Day. Hope all is well.

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

    Thanks.

    0 comments No comments