openapi: 3.0.3 info: title: Sanity HTTP API description: >- The Sanity HTTP API provides access to the Sanity Content Lake platform, enabling querying, mutating, and managing structured content. The API supports GROQ queries, real-time event streaming, asset management, project management, webhooks, scheduling, and AI-powered content agents. Authentication uses Bearer tokens generated from Sanity project settings. version: v2024-01-01 contact: name: Sanity Support url: https://www.sanity.io/docs license: name: Commercial url: https://www.sanity.io/legal/terms servers: - url: https://{projectId}.api.sanity.io/v{apiVersion} description: Sanity project-scoped API endpoint variables: projectId: description: Your Sanity project ID default: "your-project-id" apiVersion: description: API version date (YYYY-MM-DD) default: "2024-01-01" - url: https://api.sanity.io/v{apiVersion} description: Sanity management API endpoint variables: apiVersion: description: API version date default: "2024-01-01" security: - BearerAuth: [] tags: - name: Query description: GROQ query operations against Content Lake - name: Mutations description: Create, update, and delete document operations - name: Assets description: File and image asset management - name: Projects description: Project and dataset management - name: Webhooks description: Event notification configuration - name: Listen description: Real-time event streaming - name: Roles description: User role and permission management - name: Scheduling description: Content scheduling operations paths: /data/query/{dataset}: get: operationId: queryDocuments summary: Query Documents description: >- Query Content Lake using GROQ syntax. For queries under 11 KB, submit the query as a URL parameter. Use the CDN endpoint ({projectId}.apicdn.sanity.io) for edge-cached results. tags: - Query parameters: - name: dataset in: path required: true schema: type: string description: Dataset name (e.g., production) - name: query in: query required: true schema: type: string description: GROQ query string - name: perspective in: query schema: type: string enum: [drafts, published, raw] description: Content perspective to query - name: explain in: query schema: type: boolean description: Include query execution plan in response - name: resultSourceMap in: query schema: type: boolean description: Include content source map metadata responses: '200': description: Query results content: application/json: schema: $ref: '#/components/schemas/QueryResponse' '400': description: Invalid GROQ query '401': description: Unauthorized post: operationId: queryDocumentsPost summary: Query Documents (POST) description: >- Query Content Lake using GROQ syntax via POST for queries exceeding 11 KB or when query parameters need to be passed in the body. tags: - Query parameters: - name: dataset in: path required: true schema: type: string description: Dataset name requestBody: required: true content: application/json: schema: type: object required: - query properties: query: type: string description: GROQ query string params: type: object description: Query parameters as key-value pairs perspective: type: string enum: [drafts, published, raw] responses: '200': description: Query results content: application/json: schema: $ref: '#/components/schemas/QueryResponse' /data/mutate/{dataset}: post: operationId: mutateDocuments summary: Mutate Documents description: >- Apply a batch of mutations (create, createOrReplace, createIfNotExists, patch, delete) to documents in the dataset. tags: - Mutations parameters: - name: dataset in: path required: true schema: type: string description: Dataset name - name: returnIds in: query schema: type: boolean description: Return document IDs of created/modified documents - name: returnDocuments in: query schema: type: boolean description: Return full documents after mutations - name: visibility in: query schema: type: string enum: [sync, async, deferred] description: Mutation visibility mode requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/MutationsRequest' responses: '200': description: Mutation results content: application/json: schema: $ref: '#/components/schemas/MutationResponse' /assets/images/{dataset}: post: operationId: uploadImageAsset summary: Upload Image Asset description: >- Upload an image asset to the Sanity Content Lake. Supports common image formats (JPEG, PNG, WebP, GIF, SVG). tags: - Assets parameters: - name: dataset in: path required: true schema: type: string - name: filename in: query schema: type: string description: Original filename for the asset - name: label in: query schema: type: string description: Human-readable label for the asset requestBody: required: true content: image/*: schema: type: string format: binary responses: '200': description: Asset uploaded successfully content: application/json: schema: $ref: '#/components/schemas/AssetDocument' /projects: get: operationId: listProjects summary: List Projects description: >- List all Sanity projects accessible to the authenticated user, ordered by creation date. tags: - Projects responses: '200': description: List of projects content: application/json: schema: type: array items: $ref: '#/components/schemas/Project' post: operationId: createProject summary: Create Project description: Create a new Sanity project. tags: - Projects requestBody: required: true content: application/json: schema: type: object required: - displayName properties: displayName: type: string description: Human-readable project name organizationId: type: string description: Organization to associate project with responses: '200': description: Project created content: application/json: schema: $ref: '#/components/schemas/Project' /projects/{projectId}: get: operationId: getProject summary: Get Project description: Retrieve details for a specific Sanity project. tags: - Projects parameters: - name: projectId in: path required: true schema: type: string responses: '200': description: Project details content: application/json: schema: $ref: '#/components/schemas/Project' patch: operationId: updateProject summary: Update Project description: Update a Sanity project's settings. tags: - Projects parameters: - name: projectId in: path required: true schema: type: string requestBody: required: true content: application/json: schema: type: object properties: displayName: type: string metadata: type: object responses: '200': description: Project updated content: application/json: schema: $ref: '#/components/schemas/Project' /projects/{projectId}/datasets: get: operationId: listDatasets summary: List Datasets description: List all datasets for a project. tags: - Projects parameters: - name: projectId in: path required: true schema: type: string responses: '200': description: List of datasets content: application/json: schema: type: array items: $ref: '#/components/schemas/Dataset' put: operationId: createDataset summary: Create Dataset description: Create a new dataset in a project. tags: - Projects parameters: - name: projectId in: path required: true schema: type: string requestBody: required: true content: application/json: schema: type: object required: - datasetName properties: datasetName: type: string aclMode: type: string enum: [public, private] responses: '200': description: Dataset created content: application/json: schema: $ref: '#/components/schemas/Dataset' /projects/{projectId}/tokens: get: operationId: listTokens summary: List Tokens description: List all API tokens for a project. tags: - Projects parameters: - name: projectId in: path required: true schema: type: string responses: '200': description: List of tokens content: application/json: schema: type: array items: $ref: '#/components/schemas/Token' post: operationId: createToken summary: Create Token description: >- Create a new API token for a project. The token key is only returned at creation time and cannot be retrieved again. tags: - Projects parameters: - name: projectId in: path required: true schema: type: string requestBody: required: true content: application/json: schema: type: object required: - label - roleName properties: label: type: string roleName: type: string description: Role to assign to the token responses: '200': description: Token created with key content: application/json: schema: $ref: '#/components/schemas/TokenWithKey' /hooks/projects/{projectId}: get: operationId: listWebhooks summary: List Webhooks description: List all webhooks configured for a project. tags: - Webhooks parameters: - name: projectId in: path required: true schema: type: string responses: '200': description: List of webhooks content: application/json: schema: type: array items: $ref: '#/components/schemas/Webhook' post: operationId: createWebhook summary: Create Webhook description: Create a new webhook for event notifications. tags: - Webhooks parameters: - name: projectId in: path required: true schema: type: string requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/WebhookInput' responses: '201': description: Webhook created content: application/json: schema: $ref: '#/components/schemas/Webhook' /data/listen/{dataset}: get: operationId: listenForChanges summary: Listen for Changes description: >- Subscribe to real-time content changes via Server-Sent Events (SSE). The connection stays open and streams events when GROQ-matching documents are created, updated, or deleted. tags: - Listen parameters: - name: dataset in: path required: true schema: type: string - name: query in: query required: true schema: type: string description: GROQ query defining which documents to listen to - name: includeResult in: query schema: type: boolean description: Include full document in change events - name: visibility in: query schema: type: string enum: [query, transaction] responses: '200': description: SSE stream of change events content: text/event-stream: schema: type: string components: securitySchemes: BearerAuth: type: http scheme: bearer description: Sanity project API token schemas: QueryResponse: type: object properties: ms: type: integer description: Server-side processing time in milliseconds query: type: string description: The submitted query result: description: Query result (object, array, number, or null) syncTags: type: array items: type: string MutationsRequest: type: object required: - mutations properties: mutations: type: array items: type: object MutationResponse: type: object properties: transactionId: type: string results: type: array items: type: object properties: id: type: string operation: type: string AssetDocument: type: object properties: document: type: object properties: _id: type: string _type: type: string enum: [sanity.imageAsset, sanity.fileAsset] url: type: string path: type: string mimeType: type: string size: type: integer Project: type: object properties: id: type: string description: Unique project ID displayName: type: string organizationId: type: string isBlocked: type: boolean createdAt: type: string format: date-time updatedAt: type: string format: date-time Dataset: type: object properties: name: type: string aclMode: type: string enum: [public, private] tags: type: array items: type: object Token: type: object properties: id: type: string label: type: string roleName: type: string createdAt: type: string format: date-time TokenWithKey: allOf: - $ref: '#/components/schemas/Token' - type: object properties: key: type: string description: The API token key (only returned at creation) Webhook: type: object properties: id: type: string name: type: string url: type: string format: uri dataset: type: string filter: type: string description: GROQ filter expression projection: type: string on: type: array items: type: string isDisabled: type: boolean createdAt: type: string format: date-time WebhookInput: type: object required: - name - url - dataset - on properties: name: type: string url: type: string format: uri dataset: type: string filter: type: string projection: type: string on: type: array items: type: string enum: [create, update, delete] secret: type: string