REST programming in SharePoint is straightforward. Microsoft has shared the latest REST way of programming for SharePoint through Graph API. Microsoft Graph APIs are a rich source of APIs for accessing various resources of Office365 like SharePoint, Users, Onedrive. We will focus on SharePoint here.
Why use Graph API in SharePoint?
- Letting developers develop from other platforms like iOS and Android
- Like AI coding. Intelligent access from different sources
- RESTful. Latest REST.
- Any programming language
Use in production is not supported due to drastic changes. Sometimes, the results were not working in v1, and I had to change to the beta version.
However, I started seeing real SharePoint projects using Graph API while freelancing and predicting that this will be a good and easy way to program in future soon by all.
We will look at how to construct a REST Url for Graph for SharePoint site.
SharePoint Site Queries
Login to Graph Explorer from the link https://developer.microsoft.com/en-us/graph/graph-explorer
Type the query and click Run Query.
Below are some sample site Queries
- Search for sites
- Get Site ID. The Site ID contains hostname,SiteCollection ID and the Web ID
- Read Site By ID
- Read Site By Path
- Read Site Pages
Comparison with SharePoint Rest Url
While working on old SharePoint REST, you would begin the SharePoint rest URL with the site link.
Example : https://xxx.sharepoint.com/_api/web/title
|Read Sites Only||Create Sites also|
|Root Url : https://graph.microsoft.com/beta||Root Url : https://xxx.sharepoint.com/_api/web/title|
|Select Items ?select=Title||Select Items ?select=Title|
|Expanding ?expand=Author||Expanding ?expand=Author|
You learnt how to construct SharePoint Sites URL in Microsoft Graph:
- Read Sites by ID
- Read Sites by Path
- Read the Pages in a Site