OneNote API - get Notebooks stored in a organisation SharePoint site - sharepoint

I am currently using the Microsoft Graph Explorer to query the OneNote API to try and get Notebooks stored on a SharePoint site.
However, the Notebooks were created in teams but I can access them from a browser with our SharePoint url - not sure if this complicates anything?
The issue I am having is I am trying to get a set of Notebooks in a specific location (folder) and I am using the URL:
https://graph.microsoft.com/v1.0/sites/{organisationID}/onenote/notebooks - this does return a successful response but it has no meaningful data, only links which also return nothing meaningful.
Any help or feedback would be greatly appreciated.
Cheers

It appears you are after List pages endpoint which returns a list of pages in a OneNote, the following example demonstrates how to return Page title and contentUrl properties:
GET https://graph.microsoft.com/v1.0/sites/{site-id}/onenote/pages?$select=title,contentUrl
where contentUrl returns the URL for the page's HTML content
Since by design notebook contains one or more notebook sections and each section in turn contains one or more pages, the following query demonstrates how to retrieve pages along with associated section and notebook:
GET https://graph.microsoft.com/v1.0/sites/{site-id}/onenote/pages?$expand=parentSection,parentNotebook

Related

How do I get the existing preview URL for a driveItem? (not the temporary preview functionality)

In M365 you can select the context menu of a document and click Preview.
This takes you a URL of the form:
https://site.sharepoint.com/etc.../etc/something?id=pathtodocument&parent=pathtoparent
How do I get this URL from Microsft Graph?
All of the URLs I've found so far have not quite been what I needed, I would rather not have to try to stitch together the site information, the document and parent paths myself

Sharepoint Graph API download file from Document library that are not listed as drive ("Site Pages" and others)

I'm trying to find a way in Sharepoint Graph API how download file in Document library that are not listed as drive (Site Pages and others).
If I enumerating lists, I see "Site Pages" in lists:
https://graph.microsoft.com/v1.0/sites/<site id>/lists
I even can enumerate item in list :
https://graph.microsoft.com/v1.0/sites/<site id>/lists/<list id>/items
But I can't find a way to get a content (download) those items (files).
All available url to download file (get content) are next:
GET /drives/{drive-id}/items/{item-id}/content
GET /groups/{group-id}/drive/items/{item-id}/content
GET /me/drive/root:/{item-path}:/content
GET /me/drive/items/{item-id}/content
GET /sites/{siteId}/drive/items/{item-id}/content
GET /users/{userId}/drive/items/{item-id}/content
Doesn't provides an ability to get the content.
I can't find a way to get drive id for list, and there's no url to get content from list (even if it's documents library).
Please advise.
Thanks
You can call the following endpoints to retrieve:
all document libraries on a site
items in a document library (from root)
download the content of an item
This may not be the most efficient set of queries but I successfully tested in my lab tenant.
https://graph.microsoft.com/(version)/sites/(site-id)/drives
https://graph.microsoft.com/(version)/sites/(site-id)/drive/(drive-id)/root/children
https://graph.microsoft.com/(version)/sites/(site-id)/drive/(drive-id)/items/(item-id)/content
The drive resource represents a user's OneDrive or a document library in SharePoint. while site page is a page library, not document library, this is why it's not returned in drive request.
We suggest you get the file using SharePoint Rest API.
Working with files by using REST

Using Microsoft Graph API to Query Certain Sharepoint URIs with .aspx Extensions

I have a question about sharepoint combined with the graph API. I'm trying to do a GET request against a sharepoint site, but it doesn't populate when the url has a .aspx extension. For example if I do 'GET https://graph.microsoft.com/v1.0/sites/hostname.sharepoint.com:/sites/blablabla/UK' this populates a response fine, but if I do 'GET https://graph.microsoft.com/v1.0/sites/hostname.sharepoint.com:/sites/blablabla/UKDTAppKZ/something.aspx' then I get a 404 error suggesting this site doesn't exist... Could I get some clarification on how to use graph GET queries with sharepoint urls, specifically .aspx extensions?
In your first URL you're accessing the Site object for the /sites/blablabla/UK sub site, so you should get back a valid site object (assuming the URL is correct) as you indicated. To access the files in that site you need to access the Drives (Document Libraries) and then get the children or the specific item you're looking for. So the URL would look something like:
Path support isn't always consistent right now so wherever possible I like to use IDs if I know them.
So with an ID it would be:
https://graph.microsoft.com/v1.0/sites/HOSTNAME.sharepoint.com,SITECOLLECTIONGUID,SITEGUID/drives/DRIVEID/root/children
OR
https://graph.microsoft.com/v1.0/sites/HOSTNAME.sharepoint.com,SITECOLLECTIONGUID,SITEGUID/drives/DRIVEID/items/ITEMID
For Pages specifically though I would take a look at the Beta Pages API we added recently. If you want to do any operations (like publishing) to the page you'll want that API instead of the basic drive API.

Access files of Document Library site through Microsoft Graph API

I was wondering if the two following queries are actually the same or supposed to be the same:
GET https://graph.microsoft.com/beta/sharepoint/sites/{spsite-id},{spweb-id}/drives
and
GET https://graph.microsoft.com/beta/sharepoint/sites:/MYPATH:/drives
I would like to access a Document Library Item in a sharepoint site through the relative path.
Please mind that both endpoints below are the same for getting all doc libraries or drive in a site according to the current beta microsoft graph documentation. The latter becomes handy when you dont know the site id yet but the relative site url.
https://graph.microsoft.com/beta/sites/[domain.sharepoint.com]:/[relative-url]:/drives
https://graph.microsoft.com/beta/sites/[site-id]/drives
(e.g. site id: "cie493742.sharepoint.com,4af352a7-a53b-43d9-b0a3-da372b392ea0,52c490f3-3354-40b9-a3c9-fefb08cb5c88" )
Now to get the document library item
Get Document library id from list of drives
https://graph.microsoft.com/beta/sites/[site-id]/drives
Get item id from list of items
https://graph.microsoft.com/beta/sites/[site-id]/drives/[drive-id]/items
Final API call
https://graph.microsoft.com/beta/sites/[site-id]/drives/[drive-id]/items/[item-id]
you could try experimenting the Graph API from here

Set field via URL

Is it possible to have a field in the current item be changed by clicking a URL? The field would be a choice field with predefined choices.
Such as if the item field is currently:
Status: 2
If a user clicks the link, the field would now be:
Status: 3
If not, is there any other way for a user to easily change a field in the current item without actually haveing to visit the item?
Thanks!
Not Out Of The Box (OOTB) - but you've a few options.
Write an ASPX page to do what you want
Use something like SPServices and javascript to update the list item via the web services.
Use the Client Object Model (2010 only)
By the way - changing stuff on a 'get' can be dangerous as you can do malicious things - for example imagine you have a page that deletes the users account without any prompting (exact example doesn't matter) - what if someone clicks on that link by mistake or even worse what about an email sent with an image with that page as source URL - simply viewing the email could delete the users account.
It's not possible by using a GET request, but SharePoint 2010 is offering a RESTful API to manage ListItems from any client
The REST API is located within the virtual WebServices folgder under each SharePoint Site.
http://YourSharePointSite/_vti_bin/ListData.svc.
To perform an update on SharePoint ListItems you have to create a PUT Request. For more information on SharePoints REST API you should have a look at this MSDN site, there are also a lot of samples linked from this article.
Thorsten

Resources