For the complete documentation index, see llms.txt. This page is also available as Markdown.

Replace start

Beta. Catalog replace is a Beta feature and its API surface may change before GA. You must send the Batch-Beta: catalog-replace header with each replace call.

Use /catalogs/replace/start to open a replace session on a catalog that exists. A replace changes all the contents of a catalog in one atomic operation. It can also change the schema.

Batch adds the new items to a hidden revision, and the current revision continues to serve reads at the same time. This means that any campaign or automation relying on the catalog never sees an empty or partly filled catalog. The switch happens only when you complete the replace.

Beta

Replace Start

post

Beta. Catalog replace is a Beta feature and can change. Send the Batch-Beta: catalog-replace header on each call. Opens a replace session on an existing catalog. A replace changes the entire contents of a catalog, and optionally its schema, in one atomic operation. Batch adds the new items to a hidden revision. The current revision continues to serve reads at the same time. Thus campaigns do not see an empty or a partly filled catalog. Send the new items to /catalogs/replace/items. Then apply them with /catalogs/replace/complete, or discard them with /catalogs/replace/cancel. Each catalog can have only one open session at a time. The response gives a replace_token. Send this token in each subsequent call to identify the session.

Authorizations
AuthorizationstringRequired

API Key Authentication

Authentication is required in order to interact with Batch's APIs.

Batch implements authentication using API Keys, that we call the "REST API Key". You can find it on your dashboard.

Please make sure that you keep this key secret. You should never use it in client apps to call APIs from there as it would easily be extractable.

How to authenticate

In order to authenticate your requests, add your REST API Key in the Authorization header and prefix it by Bearer. Example: Authorization: Bearer bcd38d9rfb38ra28.

Header parameters
X-Batch-ProjectstringRequired

The unique project key, identifying a project on the Batch platform

Example: project_0664hxvwffvbpn278gxdyhsadddqgna6
Batch-BetastringRequired

Value of the Batch-Beta header. It is a comma-separated list of Beta contract flags. Thus one request can opt into more than one Beta contract at the same time (first-flag, second-flag). Flags are lowercase and case-sensitive, and the order does not matter. Batch rejects an unknown flag with a 400 on any endpoint. When a contract becomes generally available, Batch continues to accept its flag but the flag has no more effect. Thus you never need to remove it.

Example: catalog-replace
Body
namestringRequired

Identifier of the existing catalog to replace.

Example: products
Responses
202

The replace session is open.

application/json
replace_tokenstringRequired

Token that identifies the replace session. Send it in each subsequent replace call.

Example: eqRqTF7xFznYoG0MLs1sIqM1JhmhGLTZ7I5NtM5f
post/catalogs/replace/start
POST /2.12/catalogs/replace/start HTTP/1.1
Host: api.batch.com
Authorization: Bearer YOUR_SECRET_TOKEN
X-Batch-Project: text
Batch-Beta: text
Content-Type: application/json
Accept: */*
Content-Length: 19

{
  "name": "products"
}
{
  "replace_token": "eqRqTF7xFznYoG0MLs1sIqM1JhmhGLTZ7I5NtM5f"
}

The replace flow

A replace runs as a session of 3 calls:

  1. Start (/catalogs/replace/start) opens the session and returns a replace_token.

  2. Add items (/catalogs/replace/items) sends the new items to the pending revision.

  3. Complete (/catalogs/replace/complete) applies the pending revision.

To abandon a session instead, call Cancel (/catalogs/replace/cancel), which discards the pending revision.

Each catalog can have only one open replace session at a time.

Request structure

Route

The Catalog API has a POST endpoint that opens a replace session:

/catalogs/replace/start

Headers and authentication

See Overview → Using Project APIs. This endpoint also needs the Batch-Beta: catalog-replace header.

Post data

The body of the request must contain a valid JSON payload. The payload gives the name of the catalog to replace.

Add a fields array only if you also want to change the schema. If you do not send fields, the new revision keeps the current schema. If you send fields, Batch validates them as for catalog creation.

To reuse the current schema:

To replace with a new schema:

Responses

Success

If the call is successful, you receive an HTTP 202 confirmation and a replace_token. Send this token in each subsequent replace call. The token identifies the session.

Failure

If a replace session is already open for this catalog, you receive an HTTP 409 with the CATALOG_REPLACE_IN_PROGRESS error code.

For each other problem, you receive an error message that tells you what to do. Contact us at support@batch.com if you need more help.

Last updated