1
votes

I'm trying to create events in my personal calendar (Office 365 account) with Graph API. I create a instance on my tenant on Azure with the following delegated permissions: Calendars.Read, Calendars.ReadWrite, email, offline_access, openid, profile and User.Read.

The oAuth2 sign-in occours as expected and I receive both the bearer_token and the refresh_token, using the /.default scope. But when I try to make the request:

POST /v1.0/me/calendar/events HTTP/1.1
Host: graph.microsoft.com
Authorization: Bearer eyJ0eXAi...
Content-Type: application/json

{
    "subject": "Example",
    "body": {
        "contentType": "text",
        "content": "Example description"
    },
    "start": {
        "dateTime": "2020-09-01T12:00:00.000Z",
        "timeZone": "America/Sao_Paulo"
    },
    "end": {
        "dateTime": "2020-09-01T13:00:00.000Z",
        "timeZone": "America/Sao_Paulo"
    },
    "location": {
        "displayName": "Example location",
        "locationUri": "https://example/uri"
    }
}

I get this response:

{
  "error": {
    "code": "ResourceNotFound",
    "message": "Resource could not be discovered.",
    "innerError": {
      "date": "2020-08-31T22:18:15",
      "request-id": "f03d0bdf-1a9c-41f4-a236-1c5a41a5d286"
    }
  }
}

I already had discarted that is a mailbox problem, because with Graph Explorer I can make the request and change my calendar, so I'm willing to think that is a permission problem.

1

1 Answers

1
votes

I found out, the problem was not with the Graph request, but with the authentication request.

When you log into Graph API with a coorporative account, the requests to get the bearer_token are:

  • https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/authorize
  • https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token.

But when you use a personal account, the endpoints are:

  • https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize
  • https://login.microsoftonline.com/consumers/oauth2/v2.0/token.

Using the tenantId will authenticate, but the user data will not be found in the tenant, giving the error I got.