Get list of recent OneNote sections and pages - microsoft-graph-api

I'm using the https://graph.microsoft.com/v1.0/me/onenote/notebooks/getRecentNotebooks endpoint to retrieve a list of the user's recent notebooks. I now want to get sections and pages for those notebooks.
getRecentNotebooks returns displayName and URLs (like oneNoteWebUrl) for each notebook, but I need an ID to use onenote/notebooks/{id}/sections. Is there a way to either:
get a list of recent sections/pages (or sections/pages of recent notebooks) directly; or
get the ID of a notebook by URL using another endpoint (in graph, I saw that there might be something in the OneNote API, but would prefer not to use that)?

The /me/onenote/notebooks/GetNotebookFromWebUrl endpoint can take care of this.

Related

Microsoft Graph API - Class Notebooks

Using Microsoft Graph API, is it possible to create/load teacher and student pages from a Class Notebook?
I would prefer to not have to create a Teams assignment if possible but fine if that's the way I have to get around it.
Unfortunately the 'old' OneNote API is not an option for my purposes.
You can use list pages endpoint to retrieve a list of page objects. If successful, this method returns a 200 OK response code and a collection of page objects in the response body.
If you know the page Id, you can directly call the get page endpoint. (If not, 1st call will help you with that.)
Use create page endpoint to create a new page in the specified section

Wild Characters in MS Graph API when fetching all the users info

I'm trying to pull all the users' info from Microsoft Graph, when I do GET https://graph.microsoft.com/beta/users/, it doesn't pull manager, directReports, etc. For that, I'm making additional API calls to
/beta/users/xxxx#xxx.com/directReports and
/users/xxxx#xxx.com/authentication/methods
Is there a way to use wildcard characters in the above, so that it fetches the directReports information for all the users? I don't want to make call for each user and method, as our Org is very big.
You can use the relationships to get these details.
For getting all users directReports you can use the below graph call.
https://graph.microsoft.com/v1.0/users?$expand=directReports
See this document.

How to retrieve pages filtered by a tag from OneNote API?

Some of my pages have a OneNote Tag in it
https://learn.microsoft.com/en-us/graph/onenote-note-tags
I would like to retrieve only pages that contain a specific tag from a notebook.
Currently, I would need to
Get all the sections from a notebook
Get all the pages from a section
Get all content from pages
check if it contains data-tag="important" (example)
Is there a better way of doing this via the ms graph? (possibly via a combination of expand/filter)
Best
To get the pages in a notebook use the HTTP call below.
https://graph.microsoft.com/v1.0/me/onenote/pages
To compare the data-tag="important" is present in the content or not, it is not possible as of now but if your data is small you can use a work around by calling the below HTTP call and compare it for each page on your end.
https://graph.microsoft.com/v1.0/me/onenote/pages/pageid/content
If you have tons of data, it would be better to raise a Uservoice for this scenario by going to the Microsoft Graph Feedback Forum so that it can be implemented in the future.

Graph API - Get recent files from a particular site collection

I'm trying to fetch recent files from SharePoint Online using Microsoft Graph.
The API I'm using is :
https://graph.microsoft.com/v1.0/me/drive/recent
But the results include files from all site collection. I need to restrict the results to only a single site collection.
After some research, I found that there is no direct API to restrict the site collection.
I also tried using adding filter like :
$filter=sharepointIds/siteId eq 'site-id'
but it was also not working. It gave a `501 (Not implemented) error.
Update:
I found another API from Graph which is
https://graph.microsoft.com/beta/me/insights/used
which is inside insights(beta) named "items viewed and modified by me"
But it again returns data across tenant and I need to restrict it to a single site collection. I guess filter conditions are not yet implemented for this API in Graph.
Is there any method to get recent files from a particular site collection? Any help is appreciated.
One correction, /me/drive/recent isn't pulling from all site collections, it's pulling from the current user's OneDrive. This includes recent files held within their drive and any recent changes to files that have been shared with them.
As for finding Recent Files from a SharePoint Document Library, you need to make this request within the context of the drive you want to pull from. For example:
https://graph.microsoft.com/v1.0/sites/root/drives/{documentLibraryId}/recent

How to get Organisation Directory list from Microsoft Graph

Is there a way we can get Directory of all users? me/people gives relevant users which is not a complete list of users. We need to access complete list of users for searching.
The /users endpoint seems to be what you're looking for. Documentation is at https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_list
For example, a call to GET https://graph.microsoft.com/v1.0/users should return a paged list of all users in the tenant.
I also recommend you take a look at the Graph explorer that has samples for querying this endpoint. You can view these by clicking the show more samples link.

Resources