Using tokens to deploy APIs
I am collaborating with another dev on a project and I’d like them to be able to deploy the api but:
1. I don’t necessarily want to add them as an administrator - is there a non-admin role, or some kind of auth token they can use to deploy the api?
2. Can I specify which datasets they can deploy for (e.g. only development and not production)?
Thanks!
You don't need to make the collaborator an Administrator. They can deploy with a non-admin role (Developer) or with a least-privilege API token passed in SANITY_AUTH_TOKEN. Limiting deploys to one dataset (say development but not production) only works with Enterprise custom roles, and even then you should test that the scoping covers GraphQL deploys.
1. Let someone deploy without Administrator
Option A: invite them with the Developer role (Growth plan and above). The built-in roles are described in Roles and Permissions Concepts:
| Role | Project infrastructure | Members and roles |
|---|---|---|
| Administrator | Full: datasets, tokens, CORS, webhooks, GraphQL, deploy | Full, including adding administrators |
| Developer | Full: datasets, tokens, CORS, webhooks, GraphQL, deploy | Invite, read, update; cannot delete members |
So a Developer can run sanity graphql deploy and sanity deploy but can't change the plan or remove members. Plan availability: Free has Administrator and Viewer only. Growth adds Editor, Developer and Contributor. Enterprise adds custom roles (pricing).
Option B: give them a robot token. If the deploy command gets a missing-rights "Unauthorized" error, the CLI errors page says the deploy needs Administrator or a deploy token, and that Write/Read+Write isn't enough. To make a token:
- In sanity.io/manage, open your project, then Settings > API > Tokens > Add new token. You need the developer or admin role to do this (API tokens).
- Choose the lowest-privilege role the dropdown offers that can deploy. Don't use Administrator: Sanity's docs warn that if a pipeline holding an admin token is compromised, the whole project is taken over (custom role recipes).
- Set an expiry if you like (30, 60 or 90 days, or a custom date). The token is shown only once.
- Share it securely. The collaborator runs:
SANITY_AUTH_TOKEN=<token> npx sanity@latest graphql deploy --dataset developmentYou can also log the CLI in with the token: echo "$SANITY_AUTH_TOKEN" | npx sanity login --with-token (CLI authentication). To revoke it later, run npx sanity tokens list, then npx sanity tokens delete <token-id>.
Enterprise: a robot-only deploy role. With the Access API you can build a role like the documented ci-deploy recipe: appliesToUsers: false, appliesToRobots: true, with sanity-project deployStudio and sanity-project-datasets read/create. Then create a robot token with roleNames: ["ci-deploy"] (recipes). That recipe targets Studio deploys. The Administrator role's GraphQL permission is listed separately as sanity-project-graphql (manage) (roles concepts), so for GraphQL deploys you'll likely need to add that permission too. Test with --dry-run before relying on it.
2. Restrict to specific datasets
- Free and Growth: no. The built-in roles apply to all datasets in the project.
- Enterprise: custom roles can be scoped to individual datasets or to dataset tags such as
dev,staging,prod(announcement). The docs show this scoping for document access, usingparams.datasetonsanity.document.filter.mode(for example astaging-editorrole that gets 403 on production). They don't document dataset scoping for the GraphQL deploy permission. Check whethernpx sanity@latest graphql deploy --dataset productionis actually blocked for that token.
Other options without Enterprise:
- Put production in a separate project so the collaborator's role or token only exists on the development project.
- Run deploys from CI on your side, where the pipeline decides which
--datasetit targets, and keep the token out of the collaborator's hands.
sanity graphql deploy also supports --dry-run, --api, --tag and --force (GraphQL CLI reference).
Show original thread9 replies
Was this answer helpful?
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.