GitHub Actions: Copying Sanity datasets fails, missing "manage datasets" permission

19 replies
Last updated: Nov 30, 2025
Copying datasets with GitHub Actions not working...I'm following this guide: https://www.sanity.io/guides/multi-environment-deployments to create an GitHub workflow action that copies the production dataset to a "staging" dataset. Because I'm using the embedded studio, I need to modify this code a bit. Here is the code from my action:

name: Copy Sanity Production Dataset
on:
  push:
    branches:
      - "feature/**"
      - "!production"
      - "!main"
      - "!staging"
jobs:
  prepare-dataset:
    runs-on: ubuntu-latest
    env:
      SANITY_TOKEN: ${{ secrets.SANITY_TOKEN }}
      SANITY_PROJECT: ${{ secrets.SANITY_PROJECT }}
    steps:
      - name: Double-check branch name
        run: |
          if [ ${GITHUB_REF##*/} = "production" ]; then exit 1; fi
          if [ ${GITHUB_REF##*/} = "main" ]; then exit 1; fi
      - name: Clone dataset from production
        run: |
          curl --request PUT \
          --url <https://api.sanity.io/v2021-06-07/projects/$SANITY_PROJECT/datasets/production/copy> \
          --header 'Authorization: Bearer '$SANITY_TOKEN \
          --header 'Content-Type: application/json' \
          --data '{
          "targetDataset": "staging",
          "skipHistory": true
          }'
And when I pushed a new "feature/whatever" branch, the action ran "successfully", but when I log in to my feature branch studio that is using the staging dataset, it does not have the data from production. One thing I'm unsure about is the part in the guide that says, "'we can create a token under the “API” section of the management console. It should have the “*manage datasets*” permission.'" When I created a token, I don't see any options that include "manage datasets". I've tried it with both "viewer" and "editor" permissions, but either way production is not getting copied to staging. What am I missing? It doesn't need Deploy Studio privileges does it? I'm not deploying this studio; it's embedded in my Remix app.
AI Update

Based on my research, I can see the issue you're running into. The dataset copy feature you're trying to use is actually an Enterprise/Business plan feature, and the "manage datasets" permission isn't something you'll find as a checkbox in the token creation UI.

The Token Permission Issue

When you create a token in the Sanity management console under the "API" tab, you'll only see these standard roles:

  • Viewer (read-only access)
  • Editor (read and write content)
  • Deploy Studio (for deploying Studio)
  • Administrator (full project access)

The dataset copy endpoint requires administrative permissions that go beyond standard Editor or Viewer roles. According to the documentation, copying datasets is a feature available to Business and Enterprise customers.

What You Need to Do

1. Use an Administrator token: Create a token with the Administrator role (not Editor or Viewer). This role has the necessary permissions to manage datasets, including copying them. The guide's reference to "manage datasets" permission means you need a token with Administrator-level access—it's not a separate checkbox option.

2. Verify your plan: The dataset copy feature is part of Advanced Dataset Management, which is only available on Business and Enterprise plans. If you're on a Free or Growth plan, this endpoint won't work even with the correct token—it will appear to succeed but won't actually copy the data.

3. Check your workflow: Your GitHub Action code looks correct, but make sure:

  • The SANITY_TOKEN secret contains an Administrator token
  • Your project is on a Business or Enterprise plan
  • The staging dataset either doesn't exist yet, or you're okay with it being overwritten

Alternative Approaches

If you're on a Free or Growth plan or don't have access to the copy endpoint, you could:

  • Use the CLI: The Sanity CLI's export/import commands work on all plans:

    sanity dataset export production backup.tar.gz
    sanity dataset import backup.tar.gz staging
  • Sanity Functions: Consider using Sanity Functions to automate dataset operations—they're serverless compute within Sanity and can handle content synchronization tasks without needing external hosting.

  • Upgrade your plan: If dataset copying is critical to your multi-environment workflow, consider upgrading to a Business or Enterprise plan.

The bottom line: The "manage datasets" permission mentioned in the guide refers to Administrator-level access, and the dataset copy API endpoint itself is a paid feature. You need both the right token role AND the right plan tier for this to work.

Show original thread
19 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.

Was this answer helpful?