Hello everyone,
There are many way to keep track on SharePoint list changes like event receiver, ChangeToken, workflows, there’s one more interesting way to keep track on SharePoint list and that is called webhook. By the time I write this article, webhooks are enabled only for SharePoint list items. A notification will be triggered when there’s a change in the SharePoint list, well to know more about SP List webhook please refer Microsoft Docs.
In this article we will look into How to subscribe to SharePoint list webhook from PostMan. PostMan is one of the easy ways to work on subscription, because CRUD on subscription is all about POST, GET, PATCH, DELETE http methods with values in body when required.
To move forward, first we need to access SharePoint from PostMan, this article will help you to Access SharePoint Online using Postman. I have already setup my postman to access SharePoint online, and I generate my accessToken which is used to access SharePoint Online site.
I want to create subscription for a List in SharePoint Online site, please follow below steps to create subscription
Step 1: Get List GUID, by going to List settings in SharePoint online site we can get List ID. In the below screenshot I am setting subscription for a list called Project Site Request.
List ID: 1d1b350e-9f9d-4474-a8cd-a25f20afb77c
Step 2: Go back to Postman, get your accessToken by following the steps from this article Access SharePoint Online using Postman and provide your accessToken in
Create Subscription
Method: POST
URL: https://<sharepointURL>/_api/web/lists(‘1d1b350e-9f9d-4474-a8cd-xxxxxx)/subscriptions
Header:
Accept: application/json;odata=verbose
Content-Type: application/json
Authorizatiosn: Bearer <accessToken>
Body:
{
“resource”: “https://<sharepointURL>/_api/web/lists(‘5C77031A-9621-4DFC-BB5D-57803A94E91D’)”,
“notificationUrl”: “https://<URL-That gets notified>”,
“expirationDateTime”: “<Date&TimeForExpiration>”
}
Once we provided resource, notificationURL (I provided azure function URL to get notification), expirationDatetime in the body, we can send the request.
Once it’s successfully subscribed, we will get the following response.
Get Subscription:
Method: GET
URL: https://<sharepointURL>/_api/web/lists(‘1d1b350e-9f9d-4474-a8cd-xxxxxx)/subscriptions
It’s easy to get the list of notification URL from SharePoint Subscription. Just change the Method type to GET
Update Subscription:
To update existing subscription, please use the Method: PATCH and change the URL by adding SubscriptionID and we can get subscription ID from above screenshot with “id” key 66097de3-5ad8-4736-xxxx-e33ba4xxxxxx, here I update the expiration date from 2018-12-31T16:00:57+00:00 to 2018-11-30T16:00:57+00:00
Method: PATCH
URL: https://<sharepointURL>/_api/web/lists(‘1d1b350e-9f9d-4474-a8cd-a25xxxxxx’)/subscriptions(‘id’)
Header:
Accept: application/json;odata=verbose
Content-Type: application/json
Authorizatiosn: Bearer <accessToken>
Body:
{
“notificationUrl”: “https://<URL-That gets notified>”,
“expirationDateTime”: “<Date&TimeForExpiration>”
}
Delete Subscription:
To delete, please change the method to delete and URL will be same as how we used in Update with subscription ID.
Method: DELETE
URL: https://<sharepointURL>/_api/web/lists(‘1d1b350e-9f9d-4474-a8cd-a25xxxxxx’)/subscriptions(‘id’)
Happy Coding
Ahamed
Leave a comment