Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Created December 5, 2025 18:32
Show Gist options
  • Select an option

  • Save james2doyle/c8f54c989c5aa35e61ebed71cd790784 to your computer and use it in GitHub Desktop.

Select an option

Save james2doyle/c8f54c989c5aa35e61ebed71cd790784 to your computer and use it in GitHub Desktop.
Full collection for Sanity.io REST HTTP API including Query, Assets, and comprehensive Mutation/Patch examples.
{
"info": {
"_postman_id": "b3e3e3e3-3e3e-3e3e-3e3e-3e3e3e3e3e3e",
"name": "Sanity HTTP API (Complete + Patches)",
"description": "Full collection for Sanity.io HTTP API including Query, Assets, and comprehensive Mutation/Patch examples.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Query",
"item": [
{
"name": "Query (GET)",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{projectId}}.api.sanity.io/{{apiVersion}}/data/query/{{dataset}}?query=*[_type == \"movie\"]",
"protocol": "https",
"host": [
"{{projectId}}",
"api",
"sanity",
"io"
],
"path": [
"{{apiVersion}}",
"data",
"query",
"{{dataset}}"
],
"query": [
{
"key": "query",
"value": "*[_type == \"movie\"]",
"description": "The GROQ query itself"
},
{
"key": "explain",
"value": "true",
"description": "Include query execution plan",
"disabled": true
}
]
},
"description": "Basic query endpoint."
},
"response": []
},
{
"name": "Query (POST)",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"query\": \"*[_type == $type]\",\n \"params\": {\n \"type\": \"movie\"\n }\n}"
},
"url": {
"raw": "https://{{projectId}}.api.sanity.io/{{apiVersion}}/data/query/{{dataset}}",
"protocol": "https",
"host": [
"{{projectId}}",
"api",
"sanity",
"io"
],
"path": [
"{{apiVersion}}",
"data",
"query",
"{{dataset}}"
]
},
"description": "POST endpoint for larger queries/params."
},
"response": []
}
]
},
{
"name": "Mutation",
"item": [
{
"name": "Create / Replace",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"mutations\": [\n {\n \"createOrReplace\": {\n \"_id\": \"movie-inception\",\n \"_type\": \"movie\",\n \"title\": \"Inception\",\n \"releaseYear\": 2010\n }\n }\n ]\n}"
},
"url": {
"raw": "https://{{projectId}}.api.sanity.io/{{apiVersion}}/data/mutate/{{dataset}}?returnIds=true&visibility=sync",
"protocol": "https",
"host": [
"{{projectId}}",
"api",
"sanity",
"io"
],
"path": [
"{{apiVersion}}",
"data",
"mutate",
"{{dataset}}"
],
"query": [
{
"key": "returnIds",
"value": "true"
},
{
"key": "visibility",
"value": "sync"
}
]
},
"description": "Creates or replaces a document."
},
"response": []
},
{
"name": "Delete",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"mutations\": [\n {\n \"delete\": {\n \"id\": \"movie-inception\"\n }\n }\n ]\n}"
},
"url": {
"raw": "https://{{projectId}}.api.sanity.io/{{apiVersion}}/data/mutate/{{dataset}}",
"protocol": "https",
"host": [
"{{projectId}}",
"api",
"sanity",
"io"
],
"path": [
"{{apiVersion}}",
"data",
"mutate",
"{{dataset}}"
]
},
"description": "Deletes a document by ID."
},
"response": []
},
{
"name": "Patches",
"item": [
{
"name": "Patch (Set / Unset)",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"mutations\": [\n {\n \"patch\": {\n \"id\": \"movie-inception\",\n \"set\": {\n \"rating\": 5,\n \"reviewed\": true\n },\n \"setIfMissing\": {\n \"viewCount\": 0\n },\n \"unset\": [\n \"temporaryFlag\",\n \"oldFieldName\"\n ]\n }\n }\n ]\n}"
},
"url": {
"raw": "https://{{projectId}}.api.sanity.io/{{apiVersion}}/data/mutate/{{dataset}}",
"protocol": "https",
"host": [
"{{projectId}}",
"api",
"sanity",
"io"
],
"path": [
"{{apiVersion}}",
"data",
"mutate",
"{{dataset}}"
]
},
"description": "Standard updates. 'set' overwrites fields, 'setIfMissing' only writes if the field doesn't exist, 'unset' removes fields."
},
"response": []
},
{
"name": "Patch (Inc / Dec)",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"mutations\": [\n {\n \"patch\": {\n \"id\": \"movie-inception\",\n \"inc\": {\n \"viewCount\": 1\n },\n \"dec\": {\n \"stock\": 1\n }\n }\n }\n ]\n}"
},
"url": {
"raw": "https://{{projectId}}.api.sanity.io/{{apiVersion}}/data/mutate/{{dataset}}",
"protocol": "https",
"host": [
"{{projectId}}",
"api",
"sanity",
"io"
],
"path": [
"{{apiVersion}}",
"data",
"mutate",
"{{dataset}}"
]
},
"description": "Increments or Decrements numeric fields. Useful for counters."
},
"response": []
},
{
"name": "Patch (Insert into Array)",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"mutations\": [\n {\n \"patch\": {\n \"id\": \"movie-inception\",\n \"insert\": {\n \"after\": \"actors[-1]\",\n \"items\": [\n { \"name\": \"Tom Hardy\", \"role\": \"Eames\" }\n ]\n }\n }\n }\n ]\n}"
},
"url": {
"raw": "https://{{projectId}}.api.sanity.io/{{apiVersion}}/data/mutate/{{dataset}}",
"protocol": "https",
"host": [
"{{projectId}}",
"api",
"sanity",
"io"
],
"path": [
"{{apiVersion}}",
"data",
"mutate",
"{{dataset}}"
]
},
"description": "Inserts items into an array. \nKey options: \n- \"after\": \"path[-1]\" (append)\n- \"before\": \"path[0]\" (prepend)\n- \"replace\": \"path[1]\""
},
"response": []
},
{
"name": "Patch (DiffMatchPatch)",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"mutations\": [\n {\n \"patch\": {\n \"id\": \"movie-inception\",\n \"diffMatchPatch\": {\n \"description\": \"@@ -1,13 +1,12 @@\\n The \\n-rabid\\n+nice\\n dog\\n\"\n }\n }\n }\n ]\n}"
},
"url": {
"raw": "https://{{projectId}}.api.sanity.io/{{apiVersion}}/data/mutate/{{dataset}}",
"protocol": "https",
"host": [
"{{projectId}}",
"api",
"sanity",
"io"
],
"path": [
"{{apiVersion}}",
"data",
"mutate",
"{{dataset}}"
]
},
"description": "Applies a Google Diff-Match-Patch to a string field."
},
"response": []
}
]
}
]
},
{
"name": "Assets",
"item": [
{
"name": "Upload Image",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "image/jpeg",
"description": "Change this to match your file type (image/png, etc)",
"type": "text"
}
],
"body": {
"mode": "file",
"file": {}
},
"url": {
"raw": "https://{{projectId}}.api.sanity.io/{{apiVersion}}/assets/images/{{dataset}}?filename=my-image.jpg&label=marketing",
"protocol": "https",
"host": [
"{{projectId}}",
"api",
"sanity",
"io"
],
"path": [
"{{apiVersion}}",
"assets",
"images",
"{{dataset}}"
],
"query": [
{
"key": "filename",
"value": "my-image.jpg"
},
{
"key": "label",
"value": "marketing"
}
]
},
"description": "Upload an image asset. Body must be binary file content."
},
"response": []
},
{
"name": "Upload File",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/pdf",
"description": "Change this to match your file type",
"type": "text"
}
],
"body": {
"mode": "file",
"file": {}
},
"url": {
"raw": "https://{{projectId}}.api.sanity.io/{{apiVersion}}/assets/files/{{dataset}}?filename=document.pdf",
"protocol": "https",
"host": [
"{{projectId}}",
"api",
"sanity",
"io"
],
"path": [
"{{apiVersion}}",
"assets",
"files",
"{{dataset}}"
],
"query": [
{
"key": "filename",
"value": "document.pdf"
},
{
"key": "label",
"value": "contracts"
}
]
},
"description": "Upload a generic file asset (PDF, Doc, etc). Body must be binary file content."
},
"response": []
}
]
}
],
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{token}}",
"type": "string"
}
]
},
"variable": [
{
"key": "projectId",
"value": "your_project_id",
"type": "string"
},
{
"key": "dataset",
"value": "production",
"type": "string"
},
{
"key": "apiVersion",
"value": "v2022-03-07",
"type": "string"
},
{
"key": "token",
"value": "",
"type": "string"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment