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.
Before you start
Section titled “Before you start”- A Write & Read key from API keys. Send it as
X-API-Key: sq_…or asAuthorization: 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 documents
Section titled “Send documents”Send up to 1,000 documents per request in a documents array:
POST /v1/collections/{id}/documentsX-API-Key: sq_your_write_keyContent-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.
| Answer | When |
|---|---|
200 | Indexed. The body counts the result: { "indexed": 2, "rejected": 0, "errors": [], "warnings": [], "documentCount": 1250 }. |
400 | A document is invalid. Nothing from the request is indexed, and the body reports each problem. Fix the listed documents and resend. |
403 | The documents would pass your plan’s document limit. |
409 | A 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.
Set the roles
Section titled “Set the roles”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}X-API-Key: sq_your_write_keyContent-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.
Delete documents
Section titled “Delete documents”A push never deletes on its own. To remove documents, send their ids, up to 1,000 per request:
POST /v1/collections/{id}/documents/deleteX-API-Key: sq_your_write_keyContent-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.
Replace everything
Section titled “Replace everything”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}/documentsX-API-Key: sq_your_write_keyContent-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 answers413. - 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
completeorerror.completecarriesstatus,uploaded,diff(added,updated,removed) andreport. - Refusals: while a sync is running, the answer is
409. A collection that syncs from a feed, a store, a database or a crawl answers400.
For a static site, index your build sends this request for you.
Check it worked
Section titled “Check it worked”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.