0
votes

I'm successfully using the Graph API for a variety of things but I need to access to the OneNote API to perform student and teacher add/remove operations on Class Notebooks. When I request a token the same way that I do for Graph with the https://www.onenote.com resource it provides one but when I try to use it to access the OneNote API no matter what (valid) request I send I get 401 - "The request does not contain a valid authentication token."

I've tried using the v1.0 endpoint to generate a token instead with the same results.

My token requests:

POST https://login.microsoftonline.com/{my tenant}/oauth2/v2.0/token HTTP/1.1 Accept: application/json Content-Type: application/x-www-form-urlencoded Host: login.microsoftonline.com Content-Length: 213 Expect: 100-continue Connection: Keep-Alive

grant_type=client_credentials&client_id={my appid}&client_secret={my secret}&tenant={my tenant}&scope=https%3A%2F%2Fwww.onenote.com%2F.default

OR

POST https://login.microsoftonline.com/{my tenant}/oauth2/token HTTP/1.1 Accept: application/json Content-Type: application/x-www-form-urlencoded Host: login.microsoftonline.com Content-Length: 161 Expect: 100-continue

grant_type=client_credentials&client_id={my appid}&client_secret={my secret}&resource=https%3A%2F%2Fwww.onenote.com

Both return something containing an access_token, like: {"token_type":"Bearer","expires_in":"3600","ext_expires_in":"3600","expires_on":"1543513719","not_before":"1543509819","resource":"https://www.onenote.com","access_token":"{a token}"}

Request: GET https://www.onenote.com/api/v1.0/myorganization/groups/{group id}/notes/ HTTP/1.1 ContentType: application/json Authorization: Bearer {token returned from /token request} Cache-Control: no-store, no-cache Host: www.onenote.com

Response: code=40001 message=The request does not contain a valid authentication token.

For reference, this question is basically a follow-up to: Adding Students with the API and Class Notebook

1

1 Answers

0
votes

You're on the right track. Resource is the right way with the 1.0 auth endpoint. Scopes need to be registered on the app portal, so you'll need to go back in and add OneNote scopes in the portal.

I'm not 100% sure, but IIRC the resource for onenote might require a trailing '/'.