See Agility CMS in action. Watch a product demo
Webhook Configuration
This guide covers configuring webhooks in Agility CMS for cache invalidation and automation.
Webhook Overview
Webhooks allow Agility CMS to notify your application when content changes, enabling automatic cache invalidation and other automation.
Webhook Events
Agility CMS can send webhooks for:
- Content Published: When content is published
- Content Updated: When content is updated
- Page Published: When a page is published
- Page Updated: When a page is updated
- Redirect Updated: When redirects are updated
Webhook Configuration
Step 1: Create Webhook Endpoint
Create a webhook endpoint in your application:
// app/api/revalidate/route.ts
export async function POST(request: Request) {
// Validate webhook signature
// Process webhook event
// Revalidate cache
return Response.json({ revalidated: true })
}
Step 2: Configure Webhook in Agility CMS
- Navigate to Settings → Webhooks
- Click "Add Webhook"
- Configure webhook:
- URL: Your webhook endpoint URL
- Events: Select events to trigger webhook
- Security Key: Use
AGILITY_SECURITY_KEYfor validation
Step 3: Validate Webhook Signature
Validate webhook requests:
const securityKey = request.headers.get("x-agility-security-key")
if (securityKey !== process.env.AGILITY_SECURITY_KEY) {
return Response.json({ error: "Unauthorized" }, { status: 401 })
}
Webhook Payload
Content Published Event
{
"state": "Published",
"instanceGuid": "your-instance-guid",
"languageCode": "en-us",
"referenceName": "posts",
"contentID": 204,
"contentVersionID": 1287,
"changeDateUTC": "2025-12-08T15:12:10.883Z"
}
Page Published Event
{
"state": "Published",
"instanceGuid": "your-instance-guid",
"languageCode": "en-us",
"pageID": 2,
"pageVersionID": 114,
"changeDateUTC": "2025-12-08T15:12:10.883Z"
}
Webhook Handler Implementation
Cache Revalidation
export async function POST(request: Request) {
const data = await request.json()
// Validate security key
const securityKey = request.headers.get("x-agility-security-key")
if (securityKey !== process.env.AGILITY_SECURITY_KEY) {
return Response.json({ error: "Unauthorized" }, { status: 401 })
}
// Only process publish events
if (data.state === "Published") {
// Revalidate content tags
if (data.referenceName) {
revalidateTag(`agility-content-${data.referenceName}-${data.languageCode}`)
revalidateTag(`agility-content-${data.contentID}-${data.languageCode}`)
}
// Revalidate page tags
if (data.pageID) {
revalidateTag(`agility-page-${data.pageID}-${data.languageCode}`)
}
// Revalidate paths
if (data.path) {
revalidatePath(data.path)
}
}
return Response.json({ revalidated: true })
}
Webhook Security
Security Best Practices
- Validate Signatures: Always validate webhook signatures
- Use Security Keys: Use security keys for validation
- Whitelist Endpoints: Restrict webhook endpoints
- Monitor Activity: Monitor webhook activity
- Handle Errors: Handle webhook errors gracefully
Troubleshooting
Webhook Not Firing
Issue: Webhook not receiving events
Solutions:
- Verify webhook URL is correct
- Check webhook is enabled
- Verify events are selected
- Check webhook logs
Invalid Signature
Issue: Webhook validation failing
Solutions:
- Verify security key matches
- Check header name is correct
- Ensure key hasn't been regenerated
Next: Troubleshooting - Admin troubleshooting
In this Article:
Was this article helpful?