Skip to content

Push over the API

Your server sends each change the moment it happens: a new product, a price, a deletion. Search has it within seconds, without waiting for a scheduled sync. To send the whole set at once instead, from a build or a nightly job, replace everything.

  • A Write & Read key from API keys. Send it as X-API-Key: sq_… or as Authorization: Bearer sq_…, and keep it on your server.
  • A collection with the API as its source. On a collection that syncs from a feed, a store, a database or a crawl, the next sync replaces what you pushed.

Send up to 1,000 documents per request in a documents array:

POST /v1/collections/{id}/documents
POST /v1/collections/{id}/documents
X-API-Key: sq_your_write_key
Content-Type: application/json
{
"documents": [
{ "id": "tee-001", "title": "Cotton T-shirt", "price": 29.0 },
{ "id": "tee-002", "title": "Linen T-shirt", "price": 39.0 }
]
}

Documents are matched by id: an existing one is updated, a new one is created. id is the only field the API requires; every other field is stored as sent.

AnswerWhen
200Indexed. The body counts the result: { "indexed": 2, "rejected": 0, "errors": [], "warnings": [], "documentCount": 1250 }.
400A document is invalid. Nothing from the request is indexed, and the body reports each problem. Fix the listed documents and resend.
403The documents would pass your plan’s document limit.
409A sync or another import is writing to the collection. Retry shortly.

warnings lists documents indexed with a change, such as a text field cut to fit 100 KB (record_too_large). Every code is in Formats and limits.

A push never sets roles from field names. Name them yourself, when you create the collection or later. PATCH merges into the current roles, and an empty string clears one:

PATCH /v1/collections/{id}
PATCH /v1/collections/{id}
X-API-Key: sq_your_write_key
Content-Type: application/json
{ "roles": { "title": "title", "url": "link", "content": "description", "price": "price" } }

A role must name a column the collection already has. price, salePrice and rating need a column of numbers, and inStock one of booleans or numbers. Otherwise the answer is 400, naming roles. POST /v1/collections takes the same roles before the first push. Roles lists every role, and Describe fields for AI covers fieldMeta.

A push never deletes on its own. To remove documents, send their ids, up to 1,000 per request:

POST /v1/collections/{id}/documents/delete
POST /v1/collections/{id}/documents/delete
X-API-Key: sq_your_write_key
Content-Type: application/json
{ "ids": ["tee-001", "tee-002"] }

The answer reports deleted, notFound (ids the collection didn’t hold) and the new documentCount. While a sync or an import is writing to the collection, it answers 409: retry shortly.

  • One document: DELETE /v1/collections/{id}/documents/{documentId}.
  • Every document: DELETE /v1/collections/{id}/documents?truncate=true. Without the flag, the request is refused.

To swap the whole collection for one snapshot, send PUT with one JSON document per line (NDJSON). Documents the snapshot doesn’t list are deleted.

PUT /v1/collections/{id}/documents
PUT /v1/collections/{id}/documents
X-API-Key: sq_your_write_key
Content-Type: application/x-ndjson
{"id": "tee-001", "title": "Cotton T-shirt", "price": 29.0}
{"id": "tee-002", "title": "Linen T-shirt", "price": 39.0}
  • Size: at most 50 MB unzipped. The body may be gzipped with Content-Encoding: gzip. A larger one answers 413.
  • Roles: the snapshot is imported under the collection’s saved roles. Without any, it answers 400: set the roles first.
  • All or nothing: a snapshot that fails validation changes nothing, and search keeps the previous documents.
  • The answer is a stream of server-sent events: progress, then complete or error. complete carries status, uploaded, diff (added, updated, removed) and report.
  • Refusals: while a sync is running, the answer is 409. A collection that syncs from a feed, a store, a database or a crawl answers 400.

For a static site, index your build sends this request for you.

Each push shows in the collection’s Sync log on the Data page as Incremental sync, with the count it indexed. GET /v1/collections/{id}/documents/{documentId} returns a document as stored.

Next: Map your fields, or open the API reference for every endpoint.