Write to a collection
Add, update, or delete rows by key, without replacing the whole collection. The collection needs a key field, which you can set when you update a collection. A row whose key already exists replaces the old row, and a row with a new key is added. To replace every row instead, use update a collection.
To delete rows, give the collection a delete_field, like deleted. A row that sets that field to true deletes the row with the same key. A row that doesn't set it to true is saved with the field as you sent it. One write request can save some rows and delete others.
Send the rows in one of three ways: in the request as data, as a file at a url, or as a file in one of your collection sources with source_id and path. Customer.io reads a file when the write runs, so a file can hold far more rows than a request body can.
Customer.io queues the write and responds right away with a write id, so large writes don't time out. Customer.io applies writes to a collection one at a time, in the order it receives them. Use look up a collection write to check the result.
Customer.io checks every row before it saves anything. If any row is invalid, Customer.io doesn't save any of them. Customer.io can handle a write of up to 500 rows all at once. If your request is larger, we apply writes 500 rows at a time. While a large write runs, a read can return some of its rows and not others. If a large write fails partway, the rows it saved stay in the collection, and you can safely send the same write again.
- Type: integercollection
_id requiredThe identifier for a collection.
- Type: array object[]datarequired
The rows to write. Each row is an object that holds the collection's key field.
- application/json
- 404
The collection
iddoes not exist. - 422
Customer.io couldn't accept the write request, and didn't queue it. The response explains what to fix. When a row in
datais invalid, each error'ssource.pointernames the row, like/data/attributes/data/1. Customer.io checks the rows in a file when the write runs, so a problem in a file shows up in the write's result instead. - application/json
{
"data": [
{
"sku": "A-100",
"price": 19
},
{
"sku": "A-101",
"price": 24
}
]
}
{
"write": {
"id": "01JD8X4Q6R2W7N3K5M9P1T0VZC",
"state": "queued"
}
}Customer.io queued the write request.