HTTP API Reference

Roles API reference

Reference documentation for the Roles HTTP endpoints.

Use the Roles API to assign roles, grants, and permissions.

Authentication

  • All requests must be authenticated.
  • Administrator or equal access is required to interact with this API.

Base API server URL

Sanity API base URL

https://api.sanity.io/{apiVersion}

Variables

  • apiVersionstringdefault: "v2021-10-04"

    API version

Project

Endpoints for managing project-level roles and permissions

List users with roles

get/projects/{projectId}/acl

List all users and their roles in a project

Path parameters

Responses

200

List of users and their roles

    items
    • The project user ID

      Example:p.....
    • rolesarray
      Example
      [{"name":"administrator","title":"Administrator"}]
      Show child attributes
      items
      • namestring

        The role name

        Example:administrator
      • titlestring

        The role title

        Example:Administrator
      • A description of the role's permissions

        Example:Administrate projects
      • isCustomboolean

        Whether this is a custom role

        Example:false
      • projectIdstring

        The ID of the project this role belongs to

        Example:3do82whm
      • grantsobject

        The grants associated with this role

    • isRobotboolean

      Whether the user is a robot

      Example:false
Examplesapplication/json
[
  {
    "projectUserId": "p.....",
    "roles": [
      {
        "name": "administrator",
        "title": "Administrator"
      }
    ],
    "isRobot": false
  }
]

Get a user's roles

get/projects/{projectId}/acl/{userId}

Get the role of a specific user in a project

Path parameters

  • projectIdstringrequired

    The ID of the project

  • userIdstringrequired

    The ID of the user

Responses

200

User role information

  • rolestring

    The role name

    Example:administrator
  • The project user ID

    Example:p.....
  • isRobotboolean

    Whether the user is a robot

    Example:false
Examplesapplication/json
{
  "role": "administrator",
  "projectUserId": "p.....",
  "isRobot": false
}

Add a role to a user

put/projects/{projectId}/acl/{userId}

Add a role to a user in a project

Path parameters

  • projectIdstringrequired

    The ID of the project

  • userIdstringrequired

    The ID of the user

Request body application/json

  • roleNamestring

    The name of the role to assign

    Example:editor
Examplesapplication/json
{
  "roleName": "editor"
}

Responses

200

Role added successfully

Delete a role from a user

delete/projects/{projectId}/acl/{userId}

Remove a role from a user in a project

Path parameters

  • projectIdstringrequired

    The ID of the project

  • userIdstringrequired

    The ID of the user

Request body application/json

  • roleNamestring

    The name of the role to assign

    Example:editor

Responses

200

Role removed successfully

List all user grants

get/projects/{projectId}/grants

List all grants for users in a project

Path parameters

Responses

200

List of user grants

  • object
Examplesapplication/json
{
  "sanity.project": [
    {
      "grants": [
        {
          "name": "createSession",
          "params": {}
        },
        {
          "name": "delete",
          "params": {}
        },
        {
          "name": "deployStudio",
          "params": {}
        },
        {
          "name": "read",
          "params": {}
        },
        {
          "name": "update",
          "params": {}
        }
      ],
      "config": {}
    }
  ]
}

Create a grant

post/projects/{projectId}/grants

Create a grant for in a project. Supply an ID from a permission resource to create a grant linked to that resource. This grant can then be assigned to a user.

Path parameters

Request body application/json

Responses

List all roles

get/projects/{projectId}/roles

List all roles in a project

Path parameters

Responses

200

List of roles

    items
    • namestring

      The role name

      Example:administrator
    • titlestring

      The role title

      Example:Administrator
    • A description of the role's permissions

      Example:Administrate projects
    • isCustomboolean

      Whether this is a custom role

      Example:false
    • projectIdstring

      The ID of the project this role belongs to

      Example:3do82whm
    • grantsobject

      The grants associated with this role

Examplesapplication/json
[
  {
    "name": "administrator",
    "title": "Administrator",
    "description": "Administrate projects",
    "isCustom": false,
    "projectId": "3do82whm",
    "grants": {
      "sanity.document.filter.mode": [
        {
          "grants": [
            {
              "name": "mode",
              "params": {
                "mode": "publish",
                "history": true,
                "datasetPolicyName": "default"
              }
            }
          ],
          "config": {
            "filter": "_id in path(\"**\")"
          }
        }
      ]
    }
  }
]

Create a role

post/projects/{projectId}/roles

Create a role in a project

Path parameters

Request body application/json

  • titlestring

    The role title

    Example:Administrator
  • A description of the role's permissions

    Example:Administrate projects
  • Whether the role applies to users

    Example:true
  • Whether the role applies to robots

    Example:false
Examplesapplication/json
{
  "title": "Administrator",
  "description": "Administrate projects",
  "appliesToUsers": true,
  "appliesToRobots": false
}

Responses

200

Role created successfully

  • namestring

    The role name

    Example:administrator
  • titlestring

    The role title

    Example:Administrator
  • A description of the role's permissions

    Example:Administrate projects
  • isCustomboolean

    Whether this is a custom role

    Example:false
  • projectIdstring

    The ID of the project this role belongs to

    Example:3do82whm
  • grantsobject

    The grants associated with this role

Examplesapplication/json
{
  "name": "administrator",
  "title": "Administrator",
  "description": "Administrate projects",
  "isCustom": true,
  "projectId": "3do82whm"
}

List permission resources

get/projects/{projectId}/permissionResourceSchemas

List all permission resources in a project

Path parameters

Responses

200

List of permission resources

    items
    • idstring

      The ID of the permission resource

      Example:srp-2ve36erw
    • titlestring

      The title of the permission resource

      Example:Sanity Document Filter
    • The description of the permission resource

      Example:Defines a permission resource for a filtered collection of Sanity documents
    • namestring

      The name of the permission resource

      Example:sanity.document.filter
    • configarray
      Show child attributes
      items
      • namestring

        The name of the config parameter

        Example:filter
      • typestring

        The type of the config parameter

        Example:string
      • titlestring

        The title of the config parameter

        Example:Filter
      • The description of the config parameter

        Example:GROQ filter limiting the document collection
    • Show child attributes
      items
      • namestring

        The name of the permission

        Example:update
      • titlestring

        The title of the permission

        Example:Update
      • The description of the permission

        Example:Update documents matching the filter
      • paramsarray
        Show child attributes
        items
        • namestring

          The name of the parameter

          Example:datasetPolicyName
        • typestring

          The type of the parameter

          Example:string
        • titlestring

          The title of the parameter

          Example:Dataset Policy Name
        • The description of the parameter

          Example:A dataset policy name to scope the permission
        • The default value of the parameter

          Example:default
Examplesapplication/json
[
  {
    "id": "srp-2ve36erw",
    "title": "Sanity Document Filter",
    "description": "Defines a permission resource for a filtered collection of Sanity documents",
    "name": "sanity.document.filter",
    "config": [
      {
        "name": "filter",
        "type": "string",
        "title": "Filter",
        "description": "GROQ filter limiting the document collection"
      }
    ],
    "permissions": [
      {
        "name": "update",
        "title": "Update",
        "description": "Update documents matching the filter",
        "params": [
          {
            "name": "datasetPolicyName",
            "type": "string",
            "title": "Dataset Policy Name",
            "description": "A dataset policy name to scope the permission",
            "defaultValue": "default"
          }
        ]
      },
      {
        "name": "read",
        "title": "Read",
        "description": "Read documents matching the filter",
        "params": [
          {
            "name": "datasetPolicyName",
            "type": "string",
            "title": "Dataset Policy Name",
            "description": "A dataset policy name to scope the permission",
            "defaultValue": "default"
          }
        ]
      },
      {
        "name": "manage",
        "title": "Manage",
        "description": "Manage documents matching the filter",
        "params": [
          {
            "name": "datasetPolicyName",
            "type": "string",
            "title": "Dataset Policy Name",
            "description": "A dataset policy name to scope the permission",
            "defaultValue": "default"
          }
        ]
      },
      {
        "name": "history",
        "title": "History",
        "description": "Read the history of documents matching the filter",
        "params": [
          {
            "name": "datasetPolicyName",
            "type": "string",
            "title": "Dataset Policy Name",
            "description": "A dataset policy name to scope the permission",
            "defaultValue": "default"
          }
        ]
      },
      {
        "name": "editHistory",
        "title": "Edit History",
        "description": "Edit the history of documents matching the filter",
        "params": [
          {
            "name": "datasetPolicyName",
            "type": "string",
            "title": "Dataset Policy Name",
            "description": "A dataset policy name to scope the permission",
            "defaultValue": "default"
          }
        ]
      },
      {
        "name": "create",
        "title": "Create",
        "description": "Create documents matching the filter",
        "params": [
          {
            "name": "datasetPolicyName",
            "type": "string",
            "title": "Dataset Policy Name",
            "description": "A dataset policy name to scope the permission",
            "defaultValue": "default"
          }
        ]
      }
    ]
  }
]

Create a permission resource schema

post/projects/{projectId}/permissionResourceSchemas

Create a permission resource schema in a project. Permission resources define what types of documents a user can interact with.

Path parameters

Request body application/json

  • idstring

    The ID of the permission resource

    Example:srp-2ve36erw
  • titlestring

    The title of the permission resource

    Example:Sanity Document Filter
  • The description of the permission resource

    Example:Defines a permission resource for a filtered collection of Sanity documents
  • namestring

    The name of the permission resource

    Example:sanity.document.filter
  • configarray
    Show child attributes
    items
    • namestring

      The name of the config parameter

      Example:filter
    • typestring

      The type of the config parameter

      Example:string
    • titlestring

      The title of the config parameter

      Example:Filter
    • The description of the config parameter

      Example:GROQ filter limiting the document collection
  • Show child attributes
    items
    • namestring

      The name of the permission

      Example:update
    • titlestring

      The title of the permission

      Example:Update
    • The description of the permission

      Example:Update documents matching the filter
    • paramsarray
      Show child attributes
      items
      • namestring

        The name of the parameter

        Example:datasetPolicyName
      • typestring

        The type of the parameter

        Example:string
      • titlestring

        The title of the parameter

        Example:Dataset Policy Name
      • The description of the parameter

        Example:A dataset policy name to scope the permission
      • The default value of the parameter

        Example:default
Examplesapplication/json
{
  "name": "sanity.document.filter",
  "title": "Sanity Document Filter",
  "description": "Defines a permission resource for a filtered collection of Sanity documents",
  "config": [
    {
      "name": "filter",
      "type": "string",
      "title": "Filter",
      "description": "GROQ filter limiting the document collection"
    }
  ]
}

Responses

200

Permission resource schema created successfully

  • idstring

    The ID of the permission resource

    Example:srp-2ve36erw
  • titlestring

    The title of the permission resource

    Example:Sanity Document Filter
  • The description of the permission resource

    Example:Defines a permission resource for a filtered collection of Sanity documents
  • namestring

    The name of the permission resource

    Example:sanity.document.filter
  • configarray
    Show child attributes
    items
    • namestring

      The name of the config parameter

      Example:filter
    • typestring

      The type of the config parameter

      Example:string
    • titlestring

      The title of the config parameter

      Example:Filter
    • The description of the config parameter

      Example:GROQ filter limiting the document collection
  • Show child attributes
    items
    • namestring

      The name of the permission

      Example:update
    • titlestring

      The title of the permission

      Example:Update
    • The description of the permission

      Example:Update documents matching the filter
    • paramsarray
      Show child attributes
      items
      • namestring

        The name of the parameter

        Example:datasetPolicyName
      • typestring

        The type of the parameter

        Example:string
      • titlestring

        The title of the parameter

        Example:Dataset Policy Name
      • The description of the parameter

        Example:A dataset policy name to scope the permission
      • The default value of the parameter

        Example:default
Examplesapplication/json
{
  "name": "sanity.document.filter",
  "title": "Sanity Document Filter",
  "id": "srp-2ve36erw",
  "config": [
    {
      "name": "filter",
      "type": "string",
      "title": "Filter",
      "description": "GROQ filter limiting the document collection"
    }
  ],
  "permissions": [
    {
      "name": "update",
      "title": "Update",
      "description": "Update documents matching the filter",
      "params": [
        {
          "name": "datasetPolicyName",
          "type": "string",
          "title": "Dataset Policy Name"
        }
      ]
    }
  ]
}

Delete a role

delete/projects/{projectId}/roles/{roleName}

Delete a role in a project

Path parameters

  • projectIdstringrequired

    The ID of the project

  • roleNamestringrequired

    The name of the role

Responses

200

Role deleted successfully

Get a role

get/projects/{projectId}/roles/{roleName}

Get a role in a project

Path parameters

  • projectIdstringrequired

    The ID of the project

  • roleNamestringrequired

    The name of the role

Responses

200

OK

  • namestring

    The role name

    Example:administrator
  • titlestring

    The role title

    Example:Administrator
  • A description of the role's permissions

    Example:Administrate projects
  • isCustomboolean

    Whether this is a custom role

    Example:false
  • projectIdstring

    The ID of the project this role belongs to

    Example:3do82whm
  • grantsobject

    The grants associated with this role

Examplesapplication/json
{
  "name": "administrator",
  "title": "Administrator",
  "description": "Administrate projects",
  "isCustom": false,
  "projectId": "3do82whm",
  "grants": {
    "sanity.document.filter.mode": [
      {
        "grants": [
          {
            "name": "mode",
            "params": {
              "mode": "publish",
              "history": true,
              "datasetPolicyName": "default"
            }
          }
        ],
        "config": {
          "filter": "_id in path(\"**\")"
        }
      }
    ]
  }
}

Update a role

put/projects/{projectId}/roles/{roleName}

Update a role in a project

Path parameters

  • projectIdstringrequired

    The ID of the project

  • roleNamestringrequired

    The name of the role

Request body application/json

  • titlestring

    The title of the role

    Example:Administrator
  • The description of the role

    Example:Administrate projects
  • Whether the role applies to users

    Example:true
  • Whether the role applies to robots

    Example:false

Responses

200

OK

  • namestring

    The role name

    Example:administrator
  • titlestring

    The role title

    Example:Administrator
  • A description of the role's permissions

    Example:Administrate projects
  • isCustomboolean

    Whether this is a custom role

    Example:false
  • projectIdstring

    The ID of the project this role belongs to

    Example:3do82whm
  • grantsobject

    The grants associated with this role

Examplesapplication/json
{
  "name": "administrator",
  "title": "Administrator",
  "description": "Administrate projects",
  "isCustom": false,
  "projectId": "3do82whm",
  "grants": {
    "sanity.document.filter.mode": [
      {
        "grants": [
          {
            "name": "mode",
            "params": {
              "mode": "publish",
              "history": true,
              "datasetPolicyName": "default"
            }
          }
        ],
        "config": {
          "filter": "_id in path(\"**\")"
        }
      }
    ]
  }
}

Organization

Endpoints for managing organization-level roles and permissions

List organization members

get/organizations/{organizationId}/acl

Get a list of all members and their roles in an organization

Path parameters

Responses

200

List of organization members and their roles

    items
    • The Sanity user ID

      Example:g...
    • rolesarray
      Example
      [{"name":"administrator","title":"Administrator"}]
      Show child attributes
      items
      • namestring

        The role name

        Example:administrator
      • titlestring

        The role title

        Example:Administrator
      • A description of the role's permissions

        Example:Administrate projects
      • isCustomboolean

        Whether this is a custom role

        Example:false
      • projectIdstring

        The ID of the project this role belongs to

        Example:3do82whm
      • grantsobject

        The grants associated with this role

Examplesapplication/json
[
  {
    "sanityUserId": "g...",
    "roles": [
      {
        "name": "administrator",
        "title": "Administrator"
      }
    ]
  },
  {
    "sanityUserId": "g...",
    "roles": [
      {
        "name": "administrator",
        "title": "Administrator"
      }
    ]
  }
]

Get the roles of a single organization member

get/organizations/{organizationId}/acl/{sanityUserId}

Get the roles of a specific member in an organization

Path parameters

Responses

200

Member roles information

  • The Sanity user ID

    Example:g...
  • rolesarray
    Example
    [{"name":"administrator","title":"Administrator"}]
    Show child attributes
    items
    • namestring

      The role name

      Example:administrator
    • titlestring

      The role title

      Example:Administrator
    • A description of the role's permissions

      Example:Administrate projects
    • isCustomboolean

      Whether this is a custom role

      Example:false
    • projectIdstring

      The ID of the project this role belongs to

      Example:3do82whm
    • grantsobject

      The grants associated with this role

Give an organization member a role

put/organizations/{organizationId}/acl/{sanityUserId}

Add a role to a member in an organization

Path parameters

Request body application/json

  • roleNamestring

    The name of the role to assign

    Example:editor
Examplesapplication/json
{
  "roleName": "editor"
}

Responses

201

Role added successfully

Get all grants for current user

get/organizations/{organizationId}/grants

Get all grants for the current user in an organization

Path parameters

Responses

200

List of grants for the current user

    items
    • namestring

      The grant name

      Example:mode
    • paramsobject

      The grant parameters

      Example
      {"mode":"publish","history":true,"datasetPolicyName":"default"}

Create/update project role mappings

post/organizations/{organizationId}/providers/{providerId}/projects/{projectId}/role-mappings

Create or update project role mappings for SAML SSO.

Robot Tokens

This endpoint cannot be accessed using robot tokens.

Authorization

Requires the update permission for the sanity.organization resource.

Path parameters

Request body application/json

  • The fallback role name (optional)

    Example:viewer
  • Show child attributes
    items
    • idstring

      The ID of an existing role mapping to update (optional)

      Example:mapping-123
    • roleNamestring

      The name of a Sanity role to assign

      Example:editor
    • groupRulestring

      The group rule (regex) to match against

      Example:.*-admin
Examplesapplication/json
{
  "fallbackRoleName": "viewer",
  "roleMappings": [
    {
      "id": "mapping-123",
      "roleName": "editor",
      "groupRule": ".*-admin"
    }
  ]
}

Responses

200

Role mappings created/updated successfully

Delete project role mappings

delete/organizations/{organizationId}/providers/{providerId}/projects/{projectId}/role-mappings

Deletes all project role mappings for a specific SSO provider and project within an organization. For use with SAML SSO implementations.

Authorization

Requires the update permission for the sanity.organization resource.

Path parameters

Responses

200

Role mappings deleted successfully

Dataset

Endpoints for managing dataset-level access control and grants

Get dataset ACL

get/projects/{projectId}/datasets/{datasetName}/acl

Get the access control list for a dataset

Path parameters

Responses

200

Dataset ACL information

    items
    • filterstring

      The filter for the ACL

      Example:_id in path("**")
    • grantsarray

      The grants for the ACL

      Example
      ["read","update","create","history"]
      Show child attributes
      items
      • string
Examplesapplication/json
[
  {
    "filter": "_id in path(\"**\")",
    "grants": [
      "read",
      "update",
      "create",
      "history"
    ]
  }
]

Get dataset grants

get/projects/{projectId}/datasets/{datasetName}/grants

Get all grants for a dataset

Path parameters

Responses

200

Dataset grants information

  • Show child attributes
    items
    • grantsarray
      Example
      [{"name":"mode","params":{"mode":"publish","history":true,"datasetPolicyName":"default"}}]
      Show child attributes
      items
      • namestring

        The grant name

        Example:mode
      • paramsobject

        The grant parameters

        Example
        {"mode":"publish","history":true,"datasetPolicyName":"default"}
    • configobject
      Show child attributes
      • filterstring

        The filter for the grants

        Example:_id in path("**")
Examplesapplication/json
{
  "sanity.document.filter.mode": [
    {
      "grants": [
        {
          "name": "mode",
          "params": {
            "mode": "publish",
            "history": true,
            "datasetPolicyName": "default"
          }
        }
      ],
      "config": {
        "filter": "_id in path(\"**\")"
      }
    }
  ]
}