Access files of Document Library site through Microsoft Graph API - sharepoint

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

Related

Sharepoint Document Library OnQuickLaunch (in site navigation) with Graph API?

I'm currently working with SPO and Microsoft Graph API on a .NET 6.0 microservice.
What I want to achieve is to create a Document Library and to have a link to it in the quick navigation on the left.
I can create the Document library successfully like this:
But the created document library is only visible in the "Site Contents" section.
What the user's I'm developing for would like to have is, as simple as: EVERY TIME a new Document Library is programmatically created a link to it SHOWS up in the navigation pane.
From a user perspective this is easily achievable from the UI:
It's just a tick.
With fiddler I saw the body of the request made when you create a Document Library via UI:
But what's the corresponding property of this simple "OnQuickLaunch" field in the Graph API list model?
I've been unable to find any reference from MS documentation, am I blind or missing something?
Would also be ok if should be, somehow, possible to add the link in the navigation pane "manually" from code via Graph API.
Something like:
POST microsoft.graph.com/v1/quickLaunch/links
with body:
{
"name":"myLink",
"url":"the/document/library/url"
}

Graph API: Get Sharepoint drive item by id if drive is unknown

I added a sharepoint file browser to my app using MS Graph API to enumerate document libraries/folder/files. When selecting a file I get a driveitem id, a drive id and a webUrl (and of course many other properties).
I would like to store a reference to the selected file in a safe way: If a file is moved to another library (on same site collection) or renamed, the reference should still be valid.
I guess for office type files, I could use the webUrl, because it is a durable link and does not change. For other file types, a file can be identified by combination of driveid and itemid and queried in graph api like
https://graph.microsoft.com/v1.0/sites/{my_site}/drives/{drive-id}/items/{item-id}
If I rename a file, the item id is not changed. That's great.
If I move a file to another library, the item id is also not changed, but the drive id changes. I didn't find a way to query for a drive id across all drives on a site collection. Is it possible? Or is my approch wrong?
If the document id feature was enabled on the site collection, I could probably use this id to identify a file. But I cannot guarantee that (and I also don't know how to search by document id in Graph API).
P.S. If there is a better way to access files by id in CSOM, I could also use this instead of Graph API...

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.

Check whether SharePoint Online URL is valid document library or not

I have a software where users of office 365 tenancy will copy / paste any url to the software and I need verify / correct that URL to a proper document library.
For example;
https://contoso.sharepoint.com/Projects/Current/Forms/AllItems.aspx
should automatically be corrected to
https://contoso.sharepoint.com/Projects/Current/
And if user types;
https://contoso.sharepoint.com/Lists/Task (Task list and NOT the library)
I should throw error saying its NOT a valid document library.
There are really lots of combination of URL to it. I can use Graph API / REST API (But NOT c# as its in PHP). I am really not able to fetch any API which can do this for me.
Any suggestion?
You could try sharepoint rest api :
https://xxxx.sharepoint.com/sites/team/_api/web/GetFolderByServerRelativeUrl('Lists/Example')/Properties
You could find the vti_x005f_listservertemplate property . it's a generic list if the value is 100 . and if value is 101, it's a Document Library .

Resources