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?
Related
I'm referring to this page https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/shares_get?view=odsp-graph-online on how to encode URIs for use with MS Graph API accessing shares.
My test URL which is a publicly shared file and seems to work fine, even if not logged in, is: https://1drv.ms/x/s!Alwuj_GU-JiCgYEI-kYrrTjyHUStlw?e=lgkUYX
Then the described process is to base64 encode the URI and then perform some character replacements and a prefix, this gives:
Base64 encoded:
aHR0cHM6Ly8xZHJ2Lm1zL3gvcyFBbHd1al9HVS1KaUNnWUVJLWtZcnJUanlIVVN0bHc/ZT1sZ2tVWVg=
After char replacements and prefix:
u!aHR0cHM6Ly8xZHJ2Lm1zL3gvcyFBbHd1al9HVS1KaUNnWUVJLWtZcnJUanlIVVN0bHc_ZT1sZ2tVWVg
That should then mean this URI should fetch the document details:
https://graph.microsoft.com/v1.0/shares/u!aHR0cHM6Ly8xZHJ2Lm1zL3gvcyFBbHd1al9HVS1KaUNnWUVJLWtZcnJUanlIVVN0bHc_ZT1sZ2tVWVg/driveItem
But the response is (EDIT):
"code": "invalidRequest",
"message": "The site in the encoded share URI is invalid.",
"innerError": {
"date": "2020-12-09T11:44:29",
"request-id": "305c6344-d59f-481b-9d28-334d72bd8ab0",
"client-request-id": "66138690-8312-a6d7-b35f-97bee7c32523"
}
It gets the same both when running on the Graph Explorer (logged in) and from our application itself.
What am I doing wrong? Have tried a lot of variations on the above, can't find anything that works.
Removing my code as part of the equation, I was able to reproduce this through the Microsoft Graph API Explorer.
First, I Do a GET https://graph.microsoft.com/v1.0/users?$filter=assignedLicenses%2fany(d%3ad%2fskuid+eq+ --actualySKUIDHere--)
I get results back like
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users",
"#odata.nextLink": "https://graph.microsoft.com/v1.0/users?$filter=assignedLicenses%2fany(d%3ad%2fskuid+eq+
--actualSKUIDHere-- )&$skiptoken=X%27 --actualtokenhere-- %27",
"value": [
{
I copy paste the nextLink into the API Explorer
ie.
https://graph.microsoft.com/v1.0/users?$filter=assignedLicenses%2fany(d%3ad%2fskuid+eq+ --actualSKUIDHere-- )&$skiptoken=X%27 --actualtokenhere-- %27
and it works with good results like above, but the next skipToken is shorter and copy & pasting it will result in the following
{
"error": {
"code": "Directory_ExpiredPageToken",
"message": "The specified page token value has expired and can no longer be included in your request.",
"innerError": {
"request-id": "4cce84ea-83c5-403a-98d2-5ad5c948fcdc",
"date": "2020-02-03T21:04:43"
}
} }
I'm assuming this is a bug but wanted to post to see if anyone else has experienced this and has a resolution
This was a temporary service issue which has been fixed since. You should not try to parse/modify the next link in your application, simply use it as provided by the service.
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.
If I want to list files in the folder with query parameter $orderBy according to the documentation, I get a response with error 501.
Here is a raw example of request:
GET /v1.0/drives/{id}/items/{id}/children?$select=name,id,folder,lastModifiedDateTime,createdDateTime,size,createdBy,lastModifiedBy,webUrl&$orderby=createdDateTime HTTP/1.1
Host: graph.microsoft.com
Authorization: Bearer <token>
The response is:
{
"error": {
"code": "notSupported",
"message": "The request is not supported by the system.",
"innerError": {
"request-id": "c925ae56-8359-4e8f-98b9-92ff0c4dfc8a",
"date": "2018-06-04T10:50:00"
}
}
}
This problem I have only with a specific OneDrive account. If I use the same API call for a different drive and folder, then it works well without any problem.
When I investigated it then it seemed like the API doesn't support parameter $orderBy with date variable inside for this account at all.
Does anyone know why I get this error for a specific account?
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"
}
}
}