Roles API reference
Reference documentation for the Roles HTTP endpoints.
Use the Roles API to assign roles, grants, and permissions.
We suggest using the newer Access API for role management instead of this legacy Roles API.
Authentication
- All requests must be authenticated.
- Most endpoints require a specific permission, such as
sanity.project.rolesorsanity.project.members. The built-in Administrator role for a project or organization has every permission its endpoints need.
Base API server URL
Sanity API base URL
https://api.sanity.io/{apiVersion}Variables
- apiVersionstringdefault:
"v2021-10-04"API version. These endpoints require v2021-06-07 or later.
Project
Endpoints for managing project-level roles and permissions
List users with roles
/projects/{projectId}/aclList the users and robots in a project and their roles. Requires the read permission on sanity.project.members.
Without the roles parameter, the list includes members who have no roles. With it, the list only includes members who have at least one of the given roles.
Path parameters
The ID of the project
Query parameters
- roles[]array
Only return users who have at least one of these roles. Use the
roles[]form, for example?roles[]=editoror?roles[]=editor&roles[]=viewer.A single plain
?roles=editorreturns400with the messageroles must be an array. Duplicate role names also return400.items
- itemsstring
Responses
List of users and their roles
- projectUserIdstring
The project user ID
Example:p..... - rolesarrayExample
[{"name":"administrator","title":"Administrator"}] - isRobotboolean
Whether the user is a robot
Example:false
items
application/json[
{
"projectUserId": "p.....",
"roles": [
{
"name": "administrator",
"title": "Administrator"
}
],
"isRobot": false
}
]The request failed validation
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 400,
"error": "Bad Request",
"message": "Validation failed",
"validation": {
"body": {
"source": "body",
"keys": [
"roleName"
],
"message": "\"roleName\" is required"
}
}
}The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The project, organization, or requested resource wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Get a user's roles
/projects/{projectId}/acl/{projectUserId}Get the roles of a specific user in a project. Requires the read permission on sanity.project.members.
Path parameters
The ID of the project
The project user ID, which starts with
p. A Sanity user ID, which starts withg, returns400.
Responses
User role information
- projectUserIdstring
The project user ID
Example:p..... - rolesarrayExample
[{"name":"administrator","title":"Administrator"}] - isRobotboolean
Whether the user is a robot
Example:false
application/json{
"projectUserId": "p.....",
"roles": [
{
"name": "administrator",
"title": "Administrator"
}
],
"isRobot": false
}The request failed validation
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 400,
"error": "Bad Request",
"message": "Validation failed",
"validation": {
"body": {
"source": "body",
"keys": [
"roleName"
],
"message": "\"roleName\" is required"
}
}
}The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The user isn't in the project, or has no roles in it
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Add a role to a user
/projects/{projectId}/acl/{projectUserId}Add one or more roles to a user in a project. Send roleName for one role, or roleNames for several. Requires the update permission on sanity.project.members.
Set deleteExistingRoles to true to also remove the user's other roles in the project. When you do, the request fails if it would leave the project without an administrator.
A role can only be given to robots if its appliesToRobots is true, and to users if its appliesToUsers is true. Only a project administrator can add or remove the administrator role.
Path parameters
The ID of the project
The project user ID, which starts with
p
Request body application/json
application/json{
"roleName": "editor"
}Responses
Roles updated. The response has no body. It also returns 201 when the user already had the roles.
The request is invalid, the role can't be given to this kind of user, the request would leave the project without an administrator, or a non-administrator tried to change the administrator role.
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The user or the role wasn't found in the project
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Delete a role from a user
/projects/{projectId}/acl/{projectUserId}Remove a role from a user in a project. Send roleName to remove one role. Omit roleName to remove all of the user's roles, which removes the user from the project and ends their project sessions. Requires the update permission on sanity.project.members.
A project must keep at least one administrator. Only a project administrator can remove the administrator role.
Path parameters
The ID of the project
The project user ID, which starts with
p
Request body application/json
- roleNamestring
The name of the role to remove. Omit it to remove all of the user's roles.
Example:editor
application/json{
"roleName": "editor"
}Responses
Role removed successfully
- object
application/json{}The request is invalid, would leave the project without an administrator, or a non-administrator tried to remove the administrator role
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The user or the role wasn't found, or the user doesn't have the role
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
List grants for the current user
/projects/{projectId}/grantsList the project-level grants for the current user in a project. The user must be a member of the project.
Path parameters
The ID of the project
Responses
The current user's project-level grants, grouped by permission resource type
- object
Grants grouped by permission resource schema name, such as
sanity.projectorsanity.document.filter.mode.
application/json{
"sanity.project": [
{
"id": "res-2kd9w0vc",
"name": "sanity-project",
"title": "Project",
"description": null,
"isCustom": false,
"config": {},
"grants": [
{
"name": "createSession",
"params": {}
},
{
"name": "delete",
"params": {}
},
{
"name": "deployStudio",
"params": {}
},
{
"name": "read",
"params": {}
},
{
"name": "update",
"params": {}
}
]
}
]
}The current user isn't a member of the project
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The project, organization, or requested resource wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Create a grant
/projects/{projectId}/grantsAdd one or more grants to a custom role in a project. A grant gives the role a permission on a permission resource. Identify the resource with permissionResourceId or permissionResourceName. Users get the grant when they're assigned the role. Requires the update permission on sanity.project.roles.
You can only add grants to custom roles. Requests for a built-in role return 400 with the message Can not modify grants on a non-custom role.
To add several grants to the same role, send roleName and a grants array instead. The grants are added together: if one fails, none are added.
Path parameters
The ID of the project
Responses
No grants were created, or at least one grant's parameters were updated. Returns the grant configuration, or an array of configurations when you send grants.
- roleNamestring
The name of the role
Example:translator - permissionNamestring
The name of the permission
Example:read - permissionResourceTypestring
The name of the permission resource schema
Example:sanity.document.filter - permissionResourceIdstring
The ID of the permission resource
Example:res-k2d8fj3a - paramsobject
The permission parameters
Example{} - tagIdstring|null
Only returned when you remove a project grant. The ID of the tag the grant applied to, if any.
- datasetIdstring|null
Only returned when you remove a project grant. The ID of the dataset the grant applied to, if any.
- roleNamestring
The name of the role
Example:translator - permissionNamestring
The name of the permission
Example:read - permissionResourceTypestring
The name of the permission resource schema
Example:sanity.document.filter - permissionResourceIdstring
The ID of the permission resource
Example:res-k2d8fj3a - paramsobject
The permission parameters
Example{} - tagIdstring|null
Only returned when you remove a project grant. The ID of the tag the grant applied to, if any.
- datasetIdstring|null
Only returned when you remove a project grant. The ID of the dataset the grant applied to, if any.
items
At least one grant was created and none were updated. Returns the grant configuration, or an array of configurations when you send grants.
- roleNamestring
The name of the role
Example:translator - permissionNamestring
The name of the permission
Example:read - permissionResourceTypestring
The name of the permission resource schema
Example:sanity.document.filter - permissionResourceIdstring
The ID of the permission resource
Example:res-k2d8fj3a - paramsobject
The permission parameters
Example{} - tagIdstring|null
Only returned when you remove a project grant. The ID of the tag the grant applied to, if any.
- datasetIdstring|null
Only returned when you remove a project grant. The ID of the dataset the grant applied to, if any.
- roleNamestring
The name of the role
Example:translator - permissionNamestring
The name of the permission
Example:read - permissionResourceTypestring
The name of the permission resource schema
Example:sanity.document.filter - permissionResourceIdstring
The ID of the permission resource
Example:res-k2d8fj3a - paramsobject
The permission parameters
Example{} - tagIdstring|null
Only returned when you remove a project grant. The ID of the tag the grant applied to, if any.
- datasetIdstring|null
Only returned when you remove a project grant. The ID of the dataset the grant applied to, if any.
items
application/json{
"roleName": "translator",
"permissionName": "read",
"permissionResourceType": "sanity.document.filter",
"permissionResourceId": "res-k2d8fj3a",
"params": {}
}The request failed validation
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 400,
"error": "Bad Request",
"message": "Validation failed",
"validation": {
"body": {
"source": "body",
"keys": [
"roleName"
],
"message": "\"roleName\" is required"
}
}
}The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The role, permission resource, permission, tag, or dataset wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
params doesn't match the permission's parameters, mode isn't read, create, or publish, or both tagName and dataset are set
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Remove a grant
/projects/{projectId}/grantsRemove one or more grants from a custom role in a project. The request body has the same shape as when you create a grant. You can only remove grants from custom roles. Requires the update permission on sanity.project.roles.
A grant only matches if params is exactly the same as when the grant was created. If nothing matches, the request still returns 200.
Path parameters
The ID of the project
Responses
Request processed. Returns the grant configuration, or an array of configurations when you send grants, whether or not a matching grant existed.
- roleNamestring
The name of the role
Example:translator - permissionNamestring
The name of the permission
Example:read - permissionResourceTypestring
The name of the permission resource schema
Example:sanity.document.filter - permissionResourceIdstring
The ID of the permission resource
Example:res-k2d8fj3a - paramsobject
The permission parameters
Example{} - tagIdstring|null
Only returned when you remove a project grant. The ID of the tag the grant applied to, if any.
- datasetIdstring|null
Only returned when you remove a project grant. The ID of the dataset the grant applied to, if any.
- roleNamestring
The name of the role
Example:translator - permissionNamestring
The name of the permission
Example:read - permissionResourceTypestring
The name of the permission resource schema
Example:sanity.document.filter - permissionResourceIdstring
The ID of the permission resource
Example:res-k2d8fj3a - paramsobject
The permission parameters
Example{} - tagIdstring|null
Only returned when you remove a project grant. The ID of the tag the grant applied to, if any.
- datasetIdstring|null
Only returned when you remove a project grant. The ID of the dataset the grant applied to, if any.
items
The request failed validation
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 400,
"error": "Bad Request",
"message": "Validation failed",
"validation": {
"body": {
"source": "body",
"keys": [
"roleName"
],
"message": "\"roleName\" is required"
}
}
}The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The role, permission resource, permission, tag, or dataset wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
params doesn't match the permission's parameters, mode isn't read, create, or publish, or both tagName and dataset are set
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
List grants for a project member
/projects/{projectId}/grants/{projectUserId}List the project-level grants for a specific member of a project. Requires the read permission on sanity.project.members.
Path parameters
The ID of the project
The project user ID of the member, which starts with
p
Responses
The member's grants, grouped by permission resource type
- object
Grants grouped by permission resource schema name, such as
sanity.projectorsanity.document.filter.mode.
The request failed validation
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 400,
"error": "Bad Request",
"message": "Validation failed",
"validation": {
"body": {
"source": "body",
"keys": [
"roleName"
],
"message": "\"roleName\" is required"
}
}
}The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The user isn't in the project
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
List all roles
/projects/{projectId}/rolesList all roles in a project, including built-in roles, ordered by name. Requires the read permission on sanity.project.roles.
A built-in role can appear twice with the same name: once for users and once for robots. Check appliesToUsers and appliesToRobots to tell them apart.
Path parameters
The ID of the project
Responses
List of roles
- namestring
The role name
Example:administrator - titlestring
The role title
Example:Administrator - descriptionstring
A description of the role's permissions. An empty string if the role has no description.
Example:Read and write access to all datasets, with full access to all project settings. - isCustomboolean
Whether this is a custom role
Example:false - projectIdstring
The ID of the project this role belongs to
Example:3do82whm - appliesToUsersboolean
Whether the role can be given to users
Example:true - appliesToRobotsboolean
Whether the role can be given to robots
Example:false - grantsobject
Grants grouped by permission resource schema name, such as
sanity.projectorsanity.document.filter.mode.
items
application/json[
{
"name": "translator",
"title": "Translator",
"description": "Edit translated documents",
"isCustom": true,
"projectId": "3do82whm",
"appliesToUsers": true,
"appliesToRobots": false,
"grants": {
"sanity.document.filter": [
{
"id": "res-k2d8fj3a",
"name": "articles",
"title": "Articles",
"description": "Documents of type article",
"isCustom": true,
"config": {
"filter": "_type == \"article\""
},
"grants": [
{
"name": "read",
"params": {}
},
{
"name": "update",
"params": {}
}
]
}
]
}
}
]The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The project, organization, or requested resource wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Create a role
/projects/{projectId}/rolesCreate a custom role in a project. Requires the create permission on sanity.project.roles, and the project must have the advancedRolesManagement feature.
Path parameters
The ID of the project
Request body application/json
The role name. Use lowercase letters, numbers, hyphens, and underscores. You can't use the name of a built-in role, or
read,write,public, orcustom.Example:translatorThe role title
Example:TranslatorA description of the role's permissions
Example:Edit translated documentsWhether the role applies to users
Example:trueWhether the role applies to robots
Example:false
application/json{
"name": "translator",
"title": "Translator",
"description": "Edit translated documents",
"appliesToUsers": true,
"appliesToRobots": false
}Responses
Role created successfully
- namestring
The role name
Example:administrator - titlestring
The role title
Example:Administrator - descriptionstring
A description of the role's permissions. An empty string if the role has no description.
Example:Read and write access to all datasets, with full access to all project settings. - isCustomboolean
Whether this is a custom role
Example:false - projectIdstring
The ID of the project this role belongs to
Example:3do82whm - appliesToUsersboolean
Whether the role can be given to users
Example:true - appliesToRobotsboolean
Whether the role can be given to robots
Example:false - grantsobject
Grants grouped by permission resource schema name, such as
sanity.projectorsanity.document.filter.mode.
application/json{
"name": "translator",
"title": "Translator",
"description": "Edit translated documents",
"isCustom": true,
"projectId": "3do82whm",
"appliesToUsers": true,
"appliesToRobots": false,
"grants": {}
}The request is invalid, the role name is reserved, or the project doesn't have the advancedRolesManagement feature
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}A role with this name already exists. Names are compared case-insensitively.
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
List permission resource schemas
/projects/{projectId}/permissionResourceSchemasList the permission resource schemas available to projects, such as sanity.project.members, sanity.document.filter, and sanity.document.filter.mode. Each schema defines a type of permission resource and the permissions you can grant on it. Requires the read permission on sanity.project.roles.
To list the permission resources in a project, use GET /projects/{projectId}/permissionResources.
Path parameters
The ID of the project
Responses
List of permission resource schemas. The example shows one entry; the response contains every project schema.
- idstring
The ID of the permission resource schema
Example:srp-2ve36erw - titlestring
The title of the permission resource schema
Example:Sanity Document Filter - descriptionstring
The description of the permission resource schema
Example:Defines a permission resource for a filtered collection of Sanity documents - namestring
The name of the permission resource schema
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 - descriptionstring
The description of the config parameter
Example:GROQ filter limiting the document collection
- permissionsarray
Show child attributes
items
- namestring
The name of the permission
Example:read - titlestring
The title of the permission
Example:Read - descriptionstring
The description of the permission
Example:Read documents matching the filter - paramsarray
Show child attributes
items
- namestring
The name of the parameter
Example:tagName - typestring
The type of the parameter
Example:string - titlestring
The title of the parameter
Example:Tag Name - descriptionstring
The description of the parameter
Example:A tag to scope the permission - requiredboolean
Whether the parameter is required. Only present on required parameters.
The default value of the parameter, if it has one
Example:false
items
application/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": "read",
"title": "Read",
"description": "Read documents matching the filter",
"params": [
{
"name": "tagName",
"type": "string",
"title": "Tag Name",
"description": "A tag to scope the permission"
},
{
"name": "dataset",
"type": "string",
"title": "Dataset Name",
"description": "A dataset to scope the permission"
}
]
},
{
"name": "create",
"title": "Create",
"description": "Create documents matching the filter",
"params": [
{
"name": "tagName",
"type": "string",
"title": "Tag Name",
"description": "A tag to scope the permission"
},
{
"name": "dataset",
"type": "string",
"title": "Dataset Name",
"description": "A dataset to scope the permission"
}
]
}
]
}
]The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The project, organization, or requested resource wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
List permission resources
/projects/{projectId}/permissionResourcesList the permission resources in a project, both built-in and custom, ordered by ID. Requires the read permission on sanity.project.roles or sanity.organization.projects.
Path parameters
The ID of the project
Responses
List of permission resources
- idstring
The ID of the permission resource
Example:res-k2d8fj3a - namestring
The name of the permission resource
Example:articles - titlestring
The title of the permission resource
Example:Articles - descriptionstring
A description of the permission resource
Example:Documents of type article - configobject
The resource configuration. For
sanity.document.filterresources,filteris a GROQ filter.Example{"filter":"_type == \"article\""} - isCustomboolean
Whether the resource was created by a user rather than by Sanity
Example:true - permissionResourceTypestring
The name of the permission resource schema the resource is based on
Example:sanity.document.filter
items
The request failed validation
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 400,
"error": "Bad Request",
"message": "Validation failed",
"validation": {
"body": {
"source": "body",
"keys": [
"roleName"
],
"message": "\"roleName\" is required"
}
}
}The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}Create a permission resource
/projects/{projectId}/permissionResourcesCreate a custom permission resource in a project. Set permissionResourceType to the name of a permission resource schema, and set config to match that schema's configuration. For sanity.document.filter, config.filter is a GROQ filter. The filter can't be empty, and can't contain a full query (*) or a dereference (->).
If you omit name, you can only refer to the resource by its ID.
Requires the update permission on sanity.project.roles, and the project must have the advancedRolesManagement feature.
Path parameters
The ID of the project
Request body application/json
The name of the permission resource schema to base the resource on
Example:sanity.document.filter- namestring
A unique name for the resource. Use lowercase letters, numbers, hyphens, and underscores. Can't start with
res-orsanity.Example:articles The title of the resource
Example:Articles- descriptionstring
A description of the resource
Example:Documents of type article Configuration that matches the permission resource schema's
config. Unknown keys return422.Example{"filter":"_type == \"article\""}
application/json{
"permissionResourceType": "sanity.document.filter",
"name": "articles",
"title": "Articles",
"description": "Documents of type article",
"config": {
"filter": "_type == \"article\""
}
}Responses
Permission resource created
- idstring
The ID of the permission resource
Example:res-k2d8fj3a - namestring
The name of the permission resource
Example:articles - titlestring
The title of the permission resource
Example:Articles - descriptionstring
A description of the permission resource
Example:Documents of type article - configobject
The resource configuration. For
sanity.document.filterresources,filteris a GROQ filter.Example{"filter":"_type == \"article\""} - isCustomboolean
Whether the resource was created by a user rather than by Sanity
Example:true - permissionResourceTypestring
The name of the permission resource schema the resource is based on
Example:sanity.document.filter
application/json{
"id": "res-k2d8fj3a",
"name": "articles",
"title": "Articles",
"description": "Documents of type article",
"config": {
"filter": "_type == \"article\""
},
"isCustom": true,
"permissionResourceType": "sanity.document.filter"
}The request is invalid, or the project doesn't have the advancedRolesManagement feature
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The permission resource schema in permissionResourceType wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
A permission resource with this name already exists
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
config is missing, doesn't match the schema, or has an invalid filter
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Get a permission resource
/projects/{projectId}/permissionResources/{resourceId}Get a permission resource in a project. Requires the read permission on sanity.project.roles or sanity.organization.projects.
Path parameters
The ID of the project
The ID or name of the permission resource. Values that start with
res-are treated as IDs.
Responses
Permission resource
- idstring
The ID of the permission resource
Example:res-k2d8fj3a - namestring
The name of the permission resource
Example:articles - titlestring
The title of the permission resource
Example:Articles - descriptionstring
A description of the permission resource
Example:Documents of type article - configobject
The resource configuration. For
sanity.document.filterresources,filteris a GROQ filter.Example{"filter":"_type == \"article\""} - isCustomboolean
Whether the resource was created by a user rather than by Sanity
Example:true - permissionResourceTypestring
The name of the permission resource schema the resource is based on
Example:sanity.document.filter
application/json{
"id": "res-k2d8fj3a",
"name": "articles",
"title": "Articles",
"description": "Documents of type article",
"config": {
"filter": "_type == \"article\""
},
"isCustom": true,
"permissionResourceType": "sanity.document.filter"
}The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The project, organization, or requested resource wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Update a permission resource
/projects/{projectId}/permissionResources/{resourceId}Update the title, description, or configuration of a permission resource. Sending config replaces the whole configuration. You can't change name or permissionResourceType.
This endpoint also updates built-in resources.
Requires the update permission on sanity.project.roles, and the project must have the advancedRolesManagement feature.
Path parameters
The ID of the project
The ID or name of the permission resource
Request body application/json
- titlestring
The title of the resource
- descriptionstring
A description of the resource
- configobject
Configuration that matches the permission resource schema's
config. Replaces the existing configuration.
application/json{
"config": {
"filter": "_type == \"article\""
}
}Responses
Permission resource updated
- idstring
The ID of the permission resource
Example:res-k2d8fj3a - namestring
The name of the permission resource
Example:articles - titlestring
The title of the permission resource
Example:Articles - descriptionstring
A description of the permission resource
Example:Documents of type article - configobject
The resource configuration. For
sanity.document.filterresources,filteris a GROQ filter.Example{"filter":"_type == \"article\""} - isCustomboolean
Whether the resource was created by a user rather than by Sanity
Example:true - permissionResourceTypestring
The name of the permission resource schema the resource is based on
Example:sanity.document.filter
application/json{
"id": "res-k2d8fj3a",
"name": "articles",
"title": "Articles",
"description": "Documents of type article",
"config": {
"filter": "_type == \"article\""
},
"isCustom": true,
"permissionResourceType": "sanity.document.filter"
}The request is invalid, or the project doesn't have the advancedRolesManagement feature
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The project, organization, or requested resource wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
config doesn't match the schema, or has an invalid filter
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Delete a permission resource
/projects/{projectId}/permissionResources/{resourceId}Delete a permission resource, and remove every grant that uses it. This endpoint also deletes built-in resources, which removes the matching grants from built-in roles.
Requires the update permission on sanity.project.roles, and the project must have the advancedRolesManagement feature.
Path parameters
The ID of the project
The ID or name of the permission resource
Responses
Permission resource deleted. The response has no body.
The request is invalid, or the project doesn't have the advancedRolesManagement feature
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The project, organization, or requested resource wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Delete a role
/projects/{projectId}/roles/{roleName}Delete a custom role in a project. You can't delete built-in roles, or roles that are assigned to users or robots. Requires the delete permission on sanity.project.roles, and the project must have the advancedRolesManagement feature.
Path parameters
The ID of the project
The name of the role
Responses
Role deleted successfully
- object
application/json{}The request is invalid, or the project doesn't have the advancedRolesManagement feature
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The project, organization, or requested resource wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The role is assigned to users or robots
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The role is a built-in role
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Get a role
/projects/{projectId}/roles/{roleName}Get a role in a project. Requires the read permission on sanity.project.roles.
Path parameters
The ID of the project
The name of the role
Responses
OK
- namestring
The role name
Example:administrator - titlestring
The role title
Example:Administrator - descriptionstring
A description of the role's permissions. An empty string if the role has no description.
Example:Read and write access to all datasets, with full access to all project settings. - isCustomboolean
Whether this is a custom role
Example:false - projectIdstring
The ID of the project this role belongs to
Example:3do82whm - appliesToUsersboolean
Whether the role can be given to users
Example:true - appliesToRobotsboolean
Whether the role can be given to robots
Example:false - grantsobject
Grants grouped by permission resource schema name, such as
sanity.projectorsanity.document.filter.mode.
application/json{
"name": "translator",
"title": "Translator",
"description": "Edit translated documents",
"isCustom": true,
"projectId": "3do82whm",
"appliesToUsers": true,
"appliesToRobots": false,
"grants": {
"sanity.document.filter": [
{
"id": "res-k2d8fj3a",
"name": "articles",
"title": "Articles",
"description": "Documents of type article",
"isCustom": true,
"config": {
"filter": "_type == \"article\""
},
"grants": [
{
"name": "read",
"params": {}
},
{
"name": "update",
"params": {}
}
]
}
]
}
}The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The project, organization, or requested resource wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Update a role
/projects/{projectId}/roles/{roleName}Update a custom role in a project. Send only the fields you want to change. You can't rename a role, and you can't update built-in roles.
Requires the create permission on sanity.project.roles, and the project must have the advancedRolesManagement feature.
Path parameters
The ID of the project
The name of the role
Request body application/json
- titlestring
The title of the role
Example:Translator - descriptionstring
The description of the role
Example:Edit translated documents - appliesToUsersboolean
Whether the role applies to users. You can't set it to
falsewhile users have the role.Example:true - appliesToRobotsboolean
Whether the role applies to robots. You can't set it to
falsewhile robots have the role.Example:false
application/json{
"title": "Translator",
"description": "Edit and review translated documents"
}Responses
OK
- namestring
The role name
Example:administrator - titlestring
The role title
Example:Administrator - descriptionstring
A description of the role's permissions. An empty string if the role has no description.
Example:Read and write access to all datasets, with full access to all project settings. - isCustomboolean
Whether this is a custom role
Example:false - projectIdstring
The ID of the project this role belongs to
Example:3do82whm - appliesToUsersboolean
Whether the role can be given to users
Example:true - appliesToRobotsboolean
Whether the role can be given to robots
Example:false - grantsobject
Grants grouped by permission resource schema name, such as
sanity.projectorsanity.document.filter.mode.
application/json{
"name": "translator",
"title": "Translator",
"description": "Edit and review translated documents",
"isCustom": true,
"projectId": "3do82whm",
"appliesToUsers": true,
"appliesToRobots": false,
"grants": {
"sanity.document.filter": [
{
"id": "res-k2d8fj3a",
"name": "articles",
"title": "Articles",
"description": "Documents of type article",
"isCustom": true,
"config": {
"filter": "_type == \"article\""
},
"grants": [
{
"name": "read",
"params": {}
},
{
"name": "update",
"params": {}
}
]
}
]
}
}The request is invalid, or the project doesn't have the advancedRolesManagement feature
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The project, organization, or requested resource wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The request sets appliesToUsers or appliesToRobots to false while users or robots have the role
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The role is a built-in role
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Organization
Endpoints for managing organization-level roles and permissions
List organization members
/organizations/{organizationId}/aclGet a list of all members and their roles in an organization. Requires the read permission on sanity.organization.members.
The list only includes roles given directly to members. Roles a member gets through project membership aren't listed.
Path parameters
The ID of the organization
Query parameters
- roles[]array
Only return members who have at least one of these roles. Use the
roles[]form, for example?roles[]=administrator.A single plain
?roles=administratorreturns400with the messageroles must be an array.items
- itemsstring
Responses
List of organization members and their roles
- sanityUserIdstring
The Sanity user ID
Example:g... - rolesarrayExample
[{"name":"administrator","title":"Administrator"}]
items
application/json[
{
"sanityUserId": "g...",
"roles": [
{
"name": "administrator",
"title": "Administrator"
}
]
},
{
"sanityUserId": "g...",
"roles": [
{
"name": "administrator",
"title": "Administrator"
}
]
}
]The request failed validation
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 400,
"error": "Bad Request",
"message": "Validation failed",
"validation": {
"body": {
"source": "body",
"keys": [
"roleName"
],
"message": "\"roleName\" is required"
}
}
}The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The project, organization, or requested resource wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Get the roles of a single organization member
/organizations/{organizationId}/acl/{sanityUserId}Get the roles of a specific member in an organization. Requires the read permission on sanity.organization.members.
Path parameters
The ID of the organization
The Sanity user ID, which starts with
g
Responses
Member roles information
- sanityUserIdstring
The Sanity user ID
Example:g... - rolesarrayExample
[{"name":"administrator","title":"Administrator"}]
application/json{
"sanityUserId": "g...",
"roles": [
{
"name": "administrator",
"title": "Administrator"
}
]
}The request failed validation
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 400,
"error": "Bad Request",
"message": "Validation failed",
"validation": {
"body": {
"source": "body",
"keys": [
"roleName"
],
"message": "\"roleName\" is required"
}
}
}The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The user has no roles in the organization
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Give an organization member a role
/organizations/{organizationId}/acl/{sanityUserId}Add a role to an existing member of an organization. You can't use this endpoint to add new members. Requires the update permission on sanity.organization.members.
Set deleteExistingRoles to true to also remove the member's other roles in the organization. When you do, the request fails if it would leave the organization without an administrator.
Path parameters
The ID of the organization
The Sanity user ID, which starts with
g
Request body application/json
The name of the role to assign
Example:administratorRemove the member's other roles in the organization
application/json{
"roleName": "administrator"
}Responses
The member already had this role. If deleteExistingRoles is true, the member's other roles are still removed. The response has no body.
Role added successfully. The response has no body.
The request is invalid, the role can't be given to users, or the request would leave the organization without an administrator
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The user isn't a member of the organization, or the role wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Remove a role from an organization member
/organizations/{organizationId}/acl/{sanityUserId}Remove a role from a member in an organization. Send roleName to remove one role. Omit roleName to remove all of the member's roles, which removes the member from the organization. Requires the update permission on sanity.organization.members.
An organization must keep at least one administrator.
Path parameters
The ID of the organization
The Sanity user ID, which starts with
g
Request body application/json
- roleNamestring
The name of the role to remove. Omit it to remove all of the user's roles.
Example:editor
application/json{
"roleName": "administrator"
}Responses
Role removed successfully
- object
application/json{}The request is invalid, or would leave the organization without an administrator
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The member or the role wasn't found, or the member doesn't have the role
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Get all grants for current user
/organizations/{organizationId}/grantsGet all grants for the current user in an organization, including grants from roles the user gets through project membership. The user must be a member of the organization.
Path parameters
The ID of the organization
Responses
Grants for the current user, grouped by permission resource type
- object
Grants grouped by permission resource schema name, such as
sanity.projectorsanity.document.filter.mode.
The current user isn't a member of the organization
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The project, organization, or requested resource wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Create an organization grant
/organizations/{organizationId}/grantsAdd a grant to a custom role in an organization. A grant gives the role a permission on a permission resource. Identify the resource with permissionResourceId or permissionResourceName.
You can only add grants to custom roles. Requests for a built-in role return 400 with the message Can not modify grants on a non-custom role. Requires the update permission on sanity.organization.roles.
Path parameters
The ID of the organization
Request body application/json
application/json{
"roleName": "custom-role",
"permissionName": "read",
"permissionResourceId": "res-k2d8fj3a"
}Responses
The grant already existed, or its parameters were updated. Returns the grant configuration.
- roleNamestring
The name of the role
Example:translator - permissionNamestring
The name of the permission
Example:read - permissionResourceTypestring
The name of the permission resource schema
Example:sanity.document.filter - permissionResourceIdstring
The ID of the permission resource
Example:res-k2d8fj3a - paramsobject
The permission parameters
Example{} - tagIdstring|null
Only returned when you remove a project grant. The ID of the tag the grant applied to, if any.
- datasetIdstring|null
Only returned when you remove a project grant. The ID of the dataset the grant applied to, if any.
Grant created. Returns the grant configuration.
- roleNamestring
The name of the role
Example:translator - permissionNamestring
The name of the permission
Example:read - permissionResourceTypestring
The name of the permission resource schema
Example:sanity.document.filter - permissionResourceIdstring
The ID of the permission resource
Example:res-k2d8fj3a - paramsobject
The permission parameters
Example{} - tagIdstring|null
Only returned when you remove a project grant. The ID of the tag the grant applied to, if any.
- datasetIdstring|null
Only returned when you remove a project grant. The ID of the dataset the grant applied to, if any.
The request failed validation
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 400,
"error": "Bad Request",
"message": "Validation failed",
"validation": {
"body": {
"source": "body",
"keys": [
"roleName"
],
"message": "\"roleName\" is required"
}
}
}The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The organization, role, permission resource, or permission wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
params doesn't match the permission's parameters, mode isn't read, create, or publish, or both tagName and dataset are set
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Remove an organization grant
/organizations/{organizationId}/grantsRemove a grant from a custom role in an organization. The request body has the same shape as when you create an organization grant. You can only remove grants from custom roles. Requires the update permission on sanity.organization.roles.
A grant only matches if params is exactly the same as when the grant was created. If nothing matches, the request still returns 200 with deletedGrants set to 0.
Path parameters
The ID of the organization
Request body application/json
application/json{
"roleName": "custom-role",
"permissionName": "read",
"permissionResourceId": "res-k2d8fj3a"
}Responses
Returns the number of grants removed
- deletedGrantsinteger
The number of grants removed
application/json{
"deletedGrants": 1
}The request failed validation
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 400,
"error": "Bad Request",
"message": "Validation failed",
"validation": {
"body": {
"source": "body",
"keys": [
"roleName"
],
"message": "\"roleName\" is required"
}
}
}The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The organization, role, permission resource, or permission wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
params doesn't match the permission's parameters, mode isn't read, create, or publish, or both tagName and dataset are set
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Create/update project role mappings
/auth/organizations/{organizationId}/providers/{providerId}/projects/{projectId}/role-mappingsCreate, update, or delete project role mappings for SAML SSO. The request changes only the mappings it names; other mappings are left alone.
- An item without
idcreates a new mapping. Sending the same item twice creates two mappings. - An item with
id,roleName, andgroupRuleupdates that mapping. - An item with
idand an empty ornullroleNameandgroupRuledeletes that mapping. fallbackRoleNamesets the role for users who match no mapping. Set it tonullto remove the fallback, or omit it to leave the fallback unchanged.
Sending roleMappings requires the project to have the authSAMLRoleMapping feature. Setting only fallbackRoleName doesn't.
Robot Tokens
This endpoint cannot be accessed using robot tokens.
Authorization
Requires the saml permission for the sanity.organization.sso resource. Send the token in the Authorization header; session cookies aren't accepted.
Path parameters
The ID of the organization
The ID of the SSO provider
The ID of the project
Request body application/json
- fallbackRoleNamestring|null
The role for users who match no mapping. Set to
nullto remove the fallback. Omit to leave it unchanged.Example:viewer - roleMappingsarray
Show child attributes
items
- idstring
The ID of an existing role mapping, as returned by this endpoint. Omit it to create a new mapping.
- roleNamestring|null
The name of a Sanity role to assign. Required unless you're deleting the mapping.
Example:editor - groupRulestring|null
A regular expression matched against the user's SAML groups. Required unless you're deleting the mapping.
Example:.*-admin
application/json{
"fallbackRoleName": "viewer",
"roleMappings": [
{
"roleName": "editor",
"groupRule": ".*-admin"
}
]
}Responses
Role mappings created or updated. Returns the mappings the request created or updated, including the fallback mapping.
The request is invalid, groupRule uses the reserved fallback value, or the Authorization header is missing
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The project doesn't have the authSAMLRoleMapping feature
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The project doesn't belong to the organization, or the provider or a mapping id wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
groupRule isn't a valid regular expression
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Delete project role mappings
/auth/organizations/{organizationId}/providers/{providerId}/projects/{projectId}/role-mappingsDeletes all project role mappings for a specific SSO provider and project within an organization, including the fallback mapping. For use with SAML SSO implementations.
Authorization
Requires the saml permission for the sanity.organization.sso resource. Send the token in the Authorization header; session cookies aren't accepted.
Path parameters
The ID of the organization
The ID of the SSO provider
The ID of the project
Responses
Role mappings deleted successfully
- object
application/json{}The Authorization header is missing
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The request has no valid token, or the token is missing a required permission
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 401,
"error": "Unauthorized",
"message": "User is missing required grant sanity.project.roles/read to perform this operation",
"code": "missing_grant"
}The project doesn't belong to the organization, or the provider wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
Dataset
Endpoints for managing dataset-level access control and grants
Get dataset ACL
/projects/{projectId}/datasets/{datasetName}/aclGet the access control list for a dataset, as it applies to the caller. Each entry pairs a GROQ filter with the permissions granted on documents that match it. Filters that use user::attributes() are resolved for the current user.
This endpoint doesn't require a token. Without one, it returns only the entries that apply to everyone.
Path parameters
The ID of the project
The name of the dataset
Responses
Dataset ACL information
- filterstring
The filter for the ACL
Example:_id in path("**") - permissionsarray
The permissions granted on documents matching the filter
Example["read","update","create","history"]Show child attributes
items
- stringenum:
"read", "update", "create", "history"
items
application/json[
{
"filter": "_id in path(\"**\")",
"permissions": [
"read",
"update",
"create",
"history"
]
}
]The request failed validation
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
application/json{
"statusCode": 400,
"error": "Bad Request",
"message": "Validation failed",
"validation": {
"body": {
"source": "body",
"keys": [
"roleName"
],
"message": "\"roleName\" is required"
}
}
}Get dataset grants
/projects/{projectId}/datasets/{datasetName}/grantsGet the current user's document grants for a dataset. The user must be a member of the project.
Path parameters
The ID of the project
The name of the dataset
Responses
The current user's document grants, grouped by permission resource type. Returns an empty object if the user has no roles.
- object
Grants grouped by permission resource schema name, such as
sanity.projectorsanity.document.filter.mode.
application/json{
"sanity.document.filter.mode": [
{
"id": "res-7hd3kq9z",
"name": "sanity-all-documents",
"title": "All documents",
"description": null,
"isCustom": false,
"config": {
"filter": "_id in path(\"**\")"
},
"grants": [
{
"name": "mode",
"params": {
"mode": "publish",
"history": true
}
}
]
}
]
}The current user isn't a member of the project
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.
The project or dataset wasn't found
- statusCodeintegerExample:
404 - errorstringExample:
Not Found - messagestringExample:
Role "translator" not found - codestring
Set to
missing_grantwhen the token is missing a required permission - validationobject
Present on validation errors. Names the invalid fields.