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'}}}
OneNote
OneNote
A family of Microsoft products that enable users to capture, organize, and reuse notes electronically.
178 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,323 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 39,736 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.