Getting started with Graph Api is not that easy. In my recent project, I had to start learning how to use the Microsoft Graph API.
While doing it I mentioned different patterns to get to my goals.
The first thing I would recommend when starting to use the graph API is the following website:
Graph Explorer — Microsoft Graph
Here you can try out different APIs on your live Tenant, get information back and even get code snippets to use to achieve your goals.
The official documentation for the graph API is currently reachable under this address: Referenz zu Microsoft Graph-REST-API, Version 1.0 — Microsoft Graph v1.0 | Microsoft Docs
Microsoft mostly describes one way to achieve your goals. In their documentation, they are using mostly the siteid when reaching SharePoint sitecollections and the driveId when using document libraries. But these are not very clean to read and you ve always have to look at how to get them. In most cases, you need to do some Queries, before you get them, like listing all SiteCollections and searching for the required one to get the site id with a request like
A typical siteid which could be found with the above request looks like the following:
{tenant}.sharepoint.com,{id},{id}
The resulting Graph call (GET) would be:
https://graph.microsoft.com/v1.0/sites/{tenant}.sharepoint.com,{id},{id}
To make it much easier and more understandable you can use a SireUrl too. This is way faster since you don’t ve to search for the siteId first. The following Url shows how to Request a SiteCollection with a SiteUrl
https://graph.microsoft.com/v1.0/sites/TENANT.sharepoint.com:/sites/SiteName
Requesting a List works exactly the same way. There is a ListId and a ListTitle which both would work for Requests. The following example shows both:
https://graph.microsoft.com/v1.0/sites/TENANT.sharepoint.com:/sites/SiteName/lists/{ListId}
https://graph.microsoft.com/v1.0/sites/TENANT.sharepoint.com:/sites/SiteName/lists/{UrlEncoded List Title}
One last thing to mention is that the GraphApi generally works better with the Ids than with the URLs / Titles. I found out, that Some APIs doesnt even work with Urls/Titles, for example, the createUploadSession function
I hope you enjoyed reading.
Yours
Carsten
About the Author:
My name is Carsten Cleve and i am working currently for RealCore Services GmbH.
I am an IT-Developer and Father and interested in Cloud Solutions with Microsoft Azure.
Reference:
Cleve, C. (2022). How To Use The Graph API With SharePoint. Available at: https://medium.com/how-tos/how-to-use-the-graph-api-with-sharepoint-ec1a0abe09e7 [Accessed: 29 April 2022].