I try get emails with client_credentials token

Willyams Yujra 20 Reputation points
2023-03-04T00:52:07.9833333+00:00

I have tried to get the folders and mails from inbox, but the service return:


INFO >>> https://graph.microsoft.com/v1.0/users/5649abd6-XXXX-XXXX-XXXX-0767bc050a17/mailfolders
INFO >>> 401
INFO >>> {
  error: {
    code: 'OrganizationFromTenantGuidNotFound',
    message: "The tenant for tenant guid 'ce8b31cb-xxxx-xxxx-xxxx-03348390cf64' does not exist.",
    innerError: {
      oAuthEventOperationId: 'a0db5745-51a3-4d84-add1-8d1aa9fbae43',
      oAuthEventcV: 'xS+BPnF2zF/LMKqaTCkG6w.1.1',
      errorUrl: 'https://aka.ms/autherrors#error-InvalidTenant',
      requestId: 'cecd0af5-27bf-4db8-92d3-7a158a685100',
      date: '2023-03-04T00:48:14'
    }
  }
}
INFO >>> https://graph.microsoft.com/v1.0/users/5649abd6-XXXX-XXXX-XXXX-0767bc050a17/mailfolders/Inbox/messages
INFO >>> 401
INFO >>> {
  error: {
    code: 'OrganizationFromTenantGuidNotFound',
    message: "The tenant for tenant guid 'ce8b31cb-xxxx-xxxx-xxxx-03348390cf64' does not exist.",
    innerError: {
      oAuthEventOperationId: '0c702d3b-1ddd-4e08-93a9-093ffb874e02',
      oAuthEventcV: 'uzb3lIQBhNPTXHJECKZgKw.1',
      errorUrl: 'https://aka.ms/autherrors#error-InvalidTenant',
      requestId: '56f99cd2-5f22-49e7-9d38-63ad18481496',
      date: '2023-03-04T00:48:15'
    }
  }
}

I have configured my app with api application permission

User's image

The token returned from https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token only work for list all users

INFO >>> https://graph.microsoft.com/v1.0/users/
INFO >>> 200
INFO >>> {
  '@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#users',
  value: [
    {
      businessPhones: [],
      displayName: '...',
      givenName: '...',
      jobTitle: null,
      mail: null,
      mobilePhone: null,
      officeLocation: null,
      preferredLanguage: 'en',
      surname: '...',
      userPrincipalName: '....',
      id: '5649abd6-XXXX-XXXX-XXXX-0767bc050a17'
    }
  ]
}
Azure Managed Applications
Azure Managed Applications
An Azure service that enables managed service providers, independent software vendors, and enterprise IT teams to deliver turnkey solutions through the Azure Marketplace or service catalog.
139 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,005 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,700 questions
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 41,941 Reputation points
    2023-03-06T06:45:45.72+00:00

    Hi @Willyams Yujra

    This is because your tenant lacks O365 licenses, you need to purchase O365 licenses for your tenants and then assign that license to your users.

    23

    Hope this helps.

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

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2023-03-04T01:12:03.46+00:00

    Hello @Willyams Yujra,

    Thanks for reaching out.

    Error 401 Unauthorized 'OrganizationFromTenantGuidNotFound' occurs when your Azure AD does not have Office 365 account to work.

    If you want to access mailfolders for your development O365 tenant, register the app in your O365 AAD tenant that you got when you created the development tenant.

    Please follow the below steps

    • You need Microsoft 365 account with subscription
    • In your azure portal login with your Office 365 account
    • Create app in Azure active directory under App registration and give permissions according to the documentation.
    • Then use your mailFolders endpoint for users.

    Hope this helps.

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

    0 comments No comments

Your answer

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