1

I make the following REST GET request: https://graph.microsoft.com/v1.0/me/onenote/notebooks

I get the following response:

{
    "error": {
        "code": "30108",
        "message": "The OneDriveForBusiness for this user account cannot be retrieved.",
        "innerError": {
            "request-id": "25926552-3157-483a-bbcd-41a7105cd531",
            "date": "2017-07-22T18:46:07"
        }
    }
}

I do not have a One Drive For Business account. Do I really need one to access the OneNote API?

Thanks.

David
  • 2,412
  • 1
  • 14
  • 22
Nils Breitmann
  • 647
  • 1
  • 4
  • 16

4 Answers4

2

Yes. In order to use the API (to access OneNote data), you must have a OneDrive (whether personal/consumer or business/Office 365) - since the OneNote cloud data is actually stored in OneDrive/SharePoint. If you have an Office 365 account, you can try going to https://portal.office.com and then click in the left-hand "waffle" button, and click OneDrive which should create your own personal OneDrive for Business.

Please take a look at https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/onenote for more details.

Also, if you are just trying out the API you could use Graph Explorer. It has some saved/sample queries that you can try. (Under Sample Queries, click show more samples and toggle the OneNote switch).

Hope this helps,

Dan Kershaw - MSFT
  • 5,833
  • 1
  • 14
  • 23
  • Thank you for the hints. The strange thing is, I use my personal account and this has a OneDrive that contains my notebooks. To get the access token, I use an Azure function configured with "Login with Azure Active Directory". Maybe this does not work for personal accounts. When I log into the Graph Explorer with my personal account and access the OneNote Rest API, then I just get "UnknownError". – Nils Breitmann Jul 23 '17 at 08:32
  • That's your problem right there. If you want to access your personal/consumer OneDrive, you need to sign in using your Microsoft Account (not your Azure AD account). I don't know if Azure Functions supports this (it might - I just don't know). To sign in with a Microsoft Account AND call Microsoft Graph, you need to acquire an access token using the v2 authorize and token endpoints. For details on this please see this topic: https://developer.microsoft.com/en-us/graph/docs/concepts/auth_overview and Register your app and Get access tokens on behalf of a user. – Dan Kershaw - MSFT Jul 24 '17 at 00:11
0

Here how I solved it in my Azure function by switching to authentication with Microsoft account and using the classic OneNote Rest API.

var request = require('request');

module.exports = function (context, req) {

    var microsoftAccountAccessToken = req.headers['x-ms-token-microsoftaccount-access-token'];

    context.log( "Microsoft Account Access Token: " + microsoftAccountAccessToken );

    request(
        {
            url: 'https://www.onenote.com/api/v1.0/me/notes/notebooks',
            method: "GET",
            headers: {
                'Authorization': 'Bearer ' + microsoftAccountAccessToken
            },
        },
        function( error, response, body )
        {
            if (!error && response.statusCode === 200) {
                context.log(body);

                context.res = {
                    body: body
                };

                context.done();
            }
            else {

                context.log("error: " + error)
                context.log("response.statusCode: " + response.statusCode)
                context.log("response.statusText: " + response.statusText)

                context.res = {
                    body: response.statusText
                };

                context.done();
            }
        }
    );
};
Nils Breitmann
  • 647
  • 1
  • 4
  • 16
0

https://learn.microsoft.com/en-us/graph/onenote-error-codes#30108

The user's personal OneDrive for Business could not be retrieved. The following table lists some possible causes.

  1. The user's personal site has not been provisioned. The user should open OneDrive for Business and follow any instructions to provision the site. If this fails, they should contact their Office 365 tenant administrator.
  2. The user's personal site is currently being provisioned. Try the request later.
  3. The user does not have a valid OneDrive for Business license. The user should contact their Office 365 tenant administrator.
  4. A network issue prevented the request from being successfully sent.
0

I tried many ways and finally I used the method mentioned here: https://learn.microsoft.com/en-us/previous-versions/office/office-365-api/how-to/onenote-auth

The auth server is login.live.com, the above page provides two methods: code and token. Both could use. After auth and get the token, I can call Graph API with that token.

Code method is simpler to demonstrate. First, open this in browser:

https://login.live.com/oauth20_authorize.srf
  ?response_type=token
  &client_id={client_id}
  &redirect_uri={redirect_uri}
  &scope={scope}

Then, after login an account, it will callback. Just copy the access_token in the callback URL. Do:

GET https://graph.microsoft.com/v1.0/me/onenote/pages
Accept: application/json
Authorization: Bearer {access_token}

The pages could be retrieved without 30108 error. These are simple test steps. I implemented in Java, and can get OneNote data through Microsoft's Graph library(com.microsoft.graph:microsoft-graph:1.5.+). As below:

IOnenotePageCollectionPage pages = graphClient.me().onenote().pages().buildRequest().get();

graphClient is IGraphServiceClient. But I implemented the authentication provider through login.live.com.

Jue
  • 1
  • 1