Webhooks
Webhooks in SharePoint are a way to receive notifications when certain events occur in SharePoint resources such as lists or libraries. They allow applications to subscribe to specific changes and get real-time updates without continuously polling the SharePoint API.
Key Features
- Real-time Notifications: Webhooks enable immediate notification of changes, improving the responsiveness of applications built on top of SharePoint.
- Event-Driven Architecture: Promote a decoupled architecture where applications respond to events rather than periodically checking for changes.
- Support for REST APIs: Webhooks are integrated into the SharePoint REST API, making it easier to manage subscriptions and handle events.
How Webhooks Work
1. Subscription Creation: An application registers a subscription by sending a POST request to the SharePoint REST API specifying the resource URL, the event type (e.g., item added, item updated), and the callback URL where notifications should be sent. 2. Event Occurrence: When the specified event occurs (e.g., a new item is added to a list), SharePoint triggers the webhook. 3. Notification Sent: SharePoint makes a POST request to the callback URL provided in the subscription with details about the event. 4. Handling Notification: The application receives the notification and can process it accordingly, such as updating its internal state or triggering further actions.
Event Types
Common SharePoint event types that can trigger webhooks include:
- Item added
- Item updated
- Item deleted
- List created
- List properties changed
Subscription Management
- Creating a Subscription: Use the POST method to create a subscription. - Retrieving Subscriptions: Use the GET method to retrieve existing subscriptions. - Deleting a Subscription: Use the DELETE method to remove an existing subscription.
Important Considerations
- Security: Ensure that the callback URL is secure and can validate incoming requests.
- Expiration: Subscriptions have an expiration time, usually set at six months, which means they need to be renewed periodically.
- Reliability: Applications should handle potential delivery failures and implement retries as necessary.
SharePoint Articles