401 Client Error: Unauthorized for url: https://graph.microsoft.com/v1.0/users/******@hotmail.com/calendar | Error Message: The token contains no permissions, or permissions can not be understood.

zerkerpure 6 Reputation points
2022-04-10T19:41:20.747+00:00

I'm trying to make a script to add Calendar events to my main calendar in outlook using python and the O365 package. But I keep running into various issues with creating a sample event. any help would be greatly appreciated. here is a screenshot of the code and error that I keep getting.

191499-screenshot-2022-04-10-at-12-17-13-creating-a-calen.png

Microsoft Security Microsoft Graph
{count} votes

2 answers

Sort by: Most helpful
  1. CarlZhao-MSFT 46,366 Reputation points
    2022-04-11T02:36:48.67+00:00

    Hi @zerkerpure

    This is because your permissions have not been granted admin consent, so the token does not contain any permissions. You'll need to run the admin consent URL in the browser, then have your global administrator log in and consent on behalf of the organization.

    https://login.microsoftonline.com/{tenant-id}/adminconsent?client_id={client-id}  
    

    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.


  2. CarlZhao-MSFT 46,366 Reputation points
    2022-04-12T11:44:40.2+00:00

    Hi @zerkerpure

    I've spent an afternoon researching it and can conclude: the /calendars endpoint does not support invited guest users, only work accounts registered through the tenant, you can use a postman test to confirm this.

    By the way, the /events endpoint also doesn't support invited guest users, the reason why you call successfully in graph explorer is because he represents the member login of the original tenant, you can call the /me endpoint to see the user id, it should be different from the user id in the current tenant. Because it is actually two identities, one is the member identity of the original tenant, and the other is the guest identity of the current tenant.


    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 Answers by the question author, which helps users to know the answer solved the author's problem.