
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI understand your challenge! You want to know who made the change that triggered your GROQ-powered webhook so you can differentiate between user-initiated changes and your robot script's changes.
The good news is there's a solution using the identity() function in your webhook projection, combined with the Users API to get full author details.
1. Add identity() to your webhook projection:
{
"projectId": sanity::projectId(),
"dataset": sanity::dataset(),
"documentId": _id,
"revisionId": _rev,
"operation": delta::operation(),
"before": before(),
"after": after(),
"author": identity(), // This gives you the user/robot ID
"logTime": now()
}2. In your webhook handler, fetch user details:
const { author } = req.body;
const userResponse = await fetch(
`https://${projectId}.api.sanity.io/v2022-04-29/users/${author}`,
{
headers: {
Authorization: `Bearer ${sanityToken}`
}
}
);
const authorResult = await userResponse.json();
const { displayName, email, sanityUserId, provider } = authorResult;The key is that robot users and human users will have different characteristics in the response:
provider values like "google", "github", etc.provider: "sanity" and typically have "robot" in their naming or metadataYou can filter based on this:
const isRobotUser = authorResult.provider === 'sanity' ||
authorResult.email?.includes('robot') ||
authorResult.displayName?.toLowerCase().includes('robot');
if (isRobotUser) {
// Skip processing - this was your script
return res.status(200).send('Robot change - skipped');
}
// Process user-initiated changes
processUserChange(body);Another approach is to tag your robot mutations explicitly when you create them:
client.mutate({
mutations: [...],
tag: 'robot-script' // Custom tag
})While mutation tags aren't directly exposed in GROQ webhook projections, you could potentially track these separately or use the identity-based approach above which is more reliable.
Pro tip: Cache the user lookup results to reduce API calls, since the same users will likely make multiple changes.
Here's a ready-to-use webhook template that includes the author information to get you started quickly.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store