MS Graph Onenote API endpoint not working - microsoft-graph-api

There are three example URLs on this page https://developer.microsoft.com/en-us/graph/docs/concepts/onenote-get-content
Only the first one works.
graph.microsoft.com/v1.0/me/onenote/notes/pages got 400 BadRequest - Resource not found for the segment 'notes'.
graph.microsoft.com/v1.0/me/onenote/pages?select=title,self got 404 Not Found with error code 20102 and The specified resource ID does not exist.
https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/2c568d5b67f2d066a2a85fb4292e8d7efe317b97/docs/overview.md the example line of
await graphClient.Me.Onenote.Sections.Request().GetAsync() is also not working. Get 20102 too.
For Full Rest URL
graph.microsoft.com/v1.0/me/onenote/notebooks works.
graph.microsoft.com/v1.0/me/onenote/notebooks/{notebook_id} works.
graph.microsoft.com/v1.0/me/onenote/notebooks/{notebook_id}/sections works.
But graph.microsoft.com/v1.0/me/onenote/notebooks/{notebook_id}/sections/{section_id} does not work.
section_id is from the section list got from graph api. It will return with 404 Not Found with error below.
{
"error": {
"code": "UnknownError",
"message": "{\r\n \"Message\": \"No HTTP resource was found that matches the request URI
'https://www.onenote.com/api/V1.0/users({user_id})/notes/notebooks({notebook_id})/sections({section_id})'.\"\r\n}",
"innerError": {
"request-id": xxxxxx,
"date": xxxxxx
}
} }
Also not working with graph.microsoft.com/v1.0/me/onenote/notebooks/{notebook_id}/sections/{section_id}/pages
How can I read one page from my Onenote? I got NO DOCS or EXAMPLES can help me now.
Where is DOC for Graph SDK?

1.I think you may need to call the API interface likeļ¼š
https://graph.microsoft.com/v1.0/users/{userid}/onenote/sections/{section-id}/pages or
https://graph.microsoft.com/v1.0/me/onenote/sections/{section-id}/pages
to read all pages from your Onenote.
2.You can call the Microsoft Graph API to get one page's content, and the request url like this:
https://graph.microsoft.com/v1.0/me/onenote/pages/{pageid}/content
3.You can get the content of the Graph API: https://developer.microsoft.com/zh-cn/graph/docs/concepts/v1-overview
4.Here are the Docs for Graph: https://developer.microsoft.com/en-us/graph/code-samples-and-sdks
5. I think you may need the graph explore to try some APIs. It has intellisense.
If you have further questions, please leave the comments below.

Related

issue with Microsoft graph api with forward slashes "/" in /me/events/{id}

I am having a similar issue to the post described here.
How to get an event ID from the HitID returned by a Microsoft Graph search query?
In my case I am not trying to do a patch, but just a lookup via the v1.0/me/events/{id} get request. I am using the search API of Microsoft graph API. It returns me a HitId with forward slashes in it. I tried to resolve it in the exact same way as the post describes, but cant seem to get it to work. My id parameter is:
AAMkADgwZjlhNmJjLWNiMGQtNGE5MS1hMDVkLTNkNTU2ZWE5ZmM5ZgBGAAAAAAAjq0f6CrWJSoJ6oKcYbrJfBwAyr2CWzX9CSrX7fgfr1AFOAAAAAAENAAAyr2CWzX9CSrX7fgfr1AFOAAV/rENQAAA=
I replaced the / with %252F and the call still fails. The new request id is:
AAMkADgwZjlhNmJjLWNiMGQtNGE5MS1hMDVkLTNkNTU2ZWE5ZmM5ZgBGAAAAAAAjq0f6CrWJSoJ6oKcYbrJfBwAyr2CWzX9CSrX7fgfr1AFOAAAAAAENAAAyr2CWzX9CSrX7fgfr1AFOAAV%252FrENQAAA=
which still fails in exactly the same way. To isolate the problem I used Microsoft Graph API explorer to test the request, which returns the following error message
{
"error": {
"code": "RequestBroker--ParseUri",
"message": "Resource not found for the segment 'rENQAAA='.",
"innerError": {
"date": "2021-03-18T07:48:24",
"request-id": "83cecc8b-f510-4cf0-b5f1-e4cd5f09e223",
"client-request-id": "530677e9-fa2d-a842-149e-a8db4939f3b8"
}
}
}
I cant seem to find any suitable documentation on how to resolve the issue.
Thanks in advance for any help.
Where ever you get / simply replace it with -. This will resolve your issue.

Resource not found for the segment 'siteCollections'

I am trying to download documents attached to a OneNote Page using the Microsoft Graph API.
I find attached documents by looking for <object> elements like this in the document:-
<object data-attachment="test.txt" type="text/plain" data="https://graph.microsoft.com/v1.0/siteCollections/contoso.sharepoint.com,eb44cb06-54aa-4c1b-b749-14a6bc939040,90c50fc9-e9d8-483c-817d-a6006510e8e8/onenote/resources/1-11dbf2c6ff9e32c6a479858c38ac4688!1-c256504c-f305-4df3-9d00-f6d72aef06fc/$value"></object>
According to this page the data attribute is the URL to the file. I make a GET request to that url, replacing $value in the URL with content according to how files are downloaded as binary as described here, authorizing my request with the token.
When I perform this request, I get HTTP Code 400 and the following in the body:-
{
"error": {
"code": "BadRequest",
"message": "Resource not found for the segment 'siteCollections'.",
"innerError": {
"date": "2020-08-14T12:32:04",
"request-id": "6b7a9242-8cc0-4df5-afb6-075735045d0d"
}
}
}
What am I doing wrong?
Replacing /siteCollections/ with /sites/ in the URL produced a URL that yielded a successful response.
Weird quirk of OneNote?

Microsoft Graph API - SendMail http 400 - API url from documentation not working

My application sends email using Microsoft Graph. We followed the documentation, this was working as expected for almost a year:
https://graph.microsoft.com/v1.0/users/me/microsoft.graph.sendmail
Since 3/8/2019, the same code sendmail API in PROD started failing with the HTTP 400 - Bad Request:
{
"error": {
"code": "TargetIdShouldNotBeMeOrWhitespace",
"message": "Id is malformed.",
"innerError": {
"request-id": "0de5a4eb-dac4-4d98-a4b4-178e503a6657",
"date": "2019-03-19T17:16:20"
}
}
}
As a part of the investigation, we found that the SendMail documentation has a different URL used in the examples than the API help section. We were successful when calling this URL:
https://graph.microsoft.com/v1.0/me/sendmail
Questions:
Clearly looks like there was some update on the Graph API happened around 3/8/2019 that disabled working of the earlier URL
Documentation has 2 URL's that are misleading/confusing: one is the API help section and one in examples. As of now the API URL in the help section is no longer working. That should be fixed with the correct URL to be used.
Why was such breaking change like this introduced that caused a PROD outage for our application?
What is the official channel to get these changes?
The correct URI is https://graph.microsoft.com/v1.0/me/microsoft.graph.sendmail (not /me)
The correct API route is: https://graph.microsoft.com/v1.0/me/sendMail
You can find more practical samples here: https://developer.microsoft.com/en-us/graph/graph-explorer#

Error when createUploadSession on OneDrive graph api for the special AppFolder

I am attempting to create an upload session in the special app folder for my OneDrive app using the Graph API. My app have the following permissions:
Files.ReadWrite
Files.ReadWrite.AppFolder
offline_access
The request looks like this
https://graph.microsoft.com/v1.0/users/xxxxxx96-2e02-4300-8ab0-a05d73xxxxxx/drive/special/approot:/documentname.docx:/createUploadSession
gives the following error:
{
"error": {
"code": "itemNotFound",
"message": "The resource could not be found.",
"innerError": {
"request-id": "7447aa01-6685-4af0-998a-64abc9b14825",
"date": "2017-04-06T10:07:46"
}
}
}
I can create an upload session on the normal root folder without any errors:
graph.microsoft.com/v1.0/users/xxxxxx96-2e02-4300-8ab0-a05d73xxxxxx/drive/root:/documentname.docx:/createUploadSession
result:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.uploadSession",
"expirationDateTime": "2017-04-06T10:32:48.5252565Z",
"nextExpectedRanges": [
"0-"
],
"uploadUrl": "......."
}
The createuploadsession method does not support special/approot. As mentioned in the documentation, these are the only paths to use:
POST /drive/root:/{path_to_item}:/createUploadSession
POST /drive/items/{parent_item_id}:/{filename}:/createUploadSession
Just wanted to clarify, since people are sometimes referring to this thread still: This syntax actually is supported. Due to the flexibility of OData syntax/support, the docs are not always 100% comprehensive about every request path that works.
I believe the actual issue is that Files.ReadWrite.AppFolder is not supported on ODB/SPO/business accounts yet (as of 2022) - it is only for personal/MSA accounts. However, there is work in progress to bring this support to SPO in the future.
The two scopes that are mentioned above are:
Files.ReadWrite - grants access to content on the caller's mysite only
Files.ReadWrite.AppFolder - has no effect on SPO/business
Files.ReadWrite.All should work in the short term, until Files.ReadWrite.AppFolder is implemented on SPO/ODB.

GraphApi API error codes

I am attempting to create a interface between our web application and the GraphApi.
I am currently struggling to handle error correctly as the documentation for graph API seems to be at best incomplete. Is there a reference to full list of errors one should expect.
An example of the issue is where I make a request after my access token has expired. The error code is not on the list (graph.microsoft.io docs/overview/errors page) and in a different format (capitalization). It also seems to vary drastically from the azure error codes such as "Request_BadRequest". This was found in an MSDN article titled "Error codes and error handling | Graph API concepts".
The document states "You may use the information returned here instead of, or in addition to the HTTP status code returned.". However, this is really hard if they are changing despite being out of beta.
example of an error response body:
{ "error": {
"code": "InvalidAuthenticationToken",
"message": "Access token has expired.",
"innerError": {
"request-id": "267438d2-4cc5-4621-9307-2af26d2f5b49",
"date": "2016-02-16T13:30:24"
}
}
}

Resources