Share via

How do i resolve a "Bad Request" error while trying to use Microsoft's OneNote API?

Karlyn G 0 Reputation points
2023-06-01T17:15:08.2366667+00:00
After running this code, I get the below error message. 

url = "https://graph.microsoft.com/v1.0/me/onenote/notebooks"
headers = {
    "Authorization": f"Bearer {access_token}"
}
response = requests.get(url, headers=headers)
notebooks = response.json()



{'error': {'code': 'BadRequest',
  'message': '/me request is only valid with delegated authentication flow.',
  'innerError': {'date': '2023-06-01T15:14:39',
   'request-id': 'xxx',
   'client-request-id': 'xxx'}}}
Microsoft Security | Microsoft Graph
Microsoft 365 and Office | OneNote | For business | Windows
0 comments No comments

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 46,456 Reputation points
    2023-06-02T02:17:18.26+00:00

    Hi @Karlyn G

    The /me endpoint represents the logged-in user, and the context with user participation is a delegated context, so you must grant delegated permissions to your application and use a delegated authentication flow to obtain an access token, such as the auth code flow or ROPC flow.

    If your context is an unattended context that only supports application permissions, then you should change the /me endpoint to the /users/{user id} endpoint.

    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.

    Was this answer helpful?


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.