Insights Using the Graph API with SharePoint

Using the Graph API with SharePoint

Using the Graph API with SharePoint

 
The Graph API provides access to SharePoint items such as site collections, lists, document libraries and files.  See the article https://www.concurrency.com/blog/november-2018/authenticate-to-the-graph-api-as-a-service  for a walkthrough on retrieval of an access token needed to use the Graph API.

Site Collections

Once authenticated to the Graph API it’s possible to retrieve the site collections for the logged in account using the url https://graph.microsoft.com/v1.0/sites?search=*
The results will contain an array of metadata for each site collection.

The key field is id, this id is in the form of <hostname>, <site collection GUID>,<site GUID> and will allow you to address that site collection directly.

If we then substitute that id string into the url https://graph.microsoft.com/v1.0/sites/<id>
we can get the metadata for that site. For the remaining examples we will use <id> as a placeholder for the site collection id from the previous query.

Sites

https://graph.microsoft.com/v1.0/sites/<id> returns the metadata for the root site of the site collection
https://graph.microsoft.com/v1.0/sites/<id>/sites returns the list of subsites for a given site collection
 

List Elements

Lists 
https://graph.microsoft.com/v1.0/sites/<id>/lists retrieves the lists for the site. The List Name element in the following urls is the display name field, not the name field.
List metadata
https://graph.microsoft.com/v1.0/sites/<id>/lists/<ListName> retrieves the metadata for that list
List Items
https://graph.microsoft.com/v1.0/sites/<id>/lists/<ListName>/items retrieves the items from the list.
List Item
https://graph.microsoft.com/v1.0/sites/<id>/lists/<ListName>/items/<ItemId>. The item ID is from the List Item metadata and is a number.

Document Libraries

The Library Name is the Display Name of the Library.
The item ID is from the item metadata and looks like: 01ISO65YJFGX6MUL7F25D23LGBAY53O7YK, this id is unique to the document library and will span folders.

Library Root Folder
https://graph.microsoft.com/v1.0/sites/<id>/lists/<LibraryName>/drive/root to get the root folder of the document library.
Library Items
https://graph.microsoft.com/v1.0/sites/<id>/lists/<LibraryName>/drive/root/children to get the root folder document metadata items.
Library Item metadata
https://graph.microsoft.com/v1.0/sites/<id>/lists/<LibraryName>/drive/items/<ItemId> to get the individual item metadata
Library Item Contents 
https://graph.microsoft.com/v1.0/sites/<id>/lists/<LibraryName>/drive/items/<ItemId>/content
 to get the individual item bytes
Library Folders
https://graph.microsoft.com/v1.0/sites/<id>/lists/<LibraryName>/drive/root/children/<FolderPath>/children to get the folder contents
 

Microsoft Graph Explorer

Use the Microsoft Graph Explorer to quickly browse the Graph API to discover the urls and properties available. https://developer.microsoft.com/en-us/graph/graph-explorer