Sanity Webhooks POST requests received without body
I can see you're experiencing an issue where Sanity webhooks are delivering POST requests but with empty bodies. This is a common problem that's typically related to how the webhook payload is being parsed in your application.
The most likely cause is missing or incorrect body parsing middleware in your Express/Node application. Sanity webhooks send their payload with a specific content type that requires proper parsing.
Here's what you need to check:
1. Add the correct body parser middleware
Sanity webhooks send data as application/json, so you need to ensure your Express app is configured to parse JSON bodies:
const express = require('express');
const app = express();
// This is crucial - add BEFORE your webhook route
app.use(express.json());
app.post('/webhook', (req, res) => {
console.log(req.body); // Should now contain the webhook payload
res.status(200).send('OK');
});2. For Vercel serverless functions
If you're using Vercel serverless functions (API routes), the body parsing works differently. Make sure you're not disabling the default body parser:
// api/webhook.js
export default function handler(req, res) {
if (req.method === 'POST') {
console.log(req.body); // Vercel parses JSON automatically
res.status(200).json({ received: true });
}
}3. Check your webhook configuration in Sanity
Make sure your webhook in the Sanity management console is properly configured to send the payload. The webhook should be sending a JSON payload by default.
4. Verify the Content-Type header
Sanity webhooks typically send with Content-Type: application/json. If your middleware is expecting a different content type, it might skip parsing the body. You can log the headers to verify:
app.post('/webhook', (req, res) => {
console.log('Headers:', req.headers);
console.log('Body:', req.body);
res.status(200).send('OK');
});Why this might have "started yesterday"
If this suddenly started happening on March 8, 2021, it's possible that:
- A deployment changed your middleware configuration
- Dependencies were updated (check if body-parser or express versions changed)
- The webhook configuration in Sanity was modified
Since you're seeing the same issue both on Vercel and locally with ngrok, this strongly suggests the issue is in your application code rather than the hosting environment.
Make sure express.json() or equivalent body parsing middleware is added before your webhook route handler, and that should resolve the empty body issue.
Show original thread18 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.