Update a collection
Update the name or replace the contents of a collection. Updating the data or url for your collection fully replaces the contents of the collection.
To set or change the collection's key field or delete field without replacing its rows, send key_field or delete_field without data or url. You can send both in one request. To remove either field, send an empty string. Changing either field can mean copying every row, so Customer.io queues the change as a write request and responds with a 202 and the write's id. Use get a write's status to see when the change is done. If a row is missing a key or repeats another row's key, the write fails with the code invalid-data, and its message names the row. If you send a field that's already set, Customer.io doesn't queue anything and responds with a 200.
When you replace the rows of a large collection, Customer.io changes only the rows that differ, and saves them in batches. While the replacement operation runs, a read can return some new rows alongside old ones. If a large replacement stops partway and can't finish, the collection is left part old and part new. Until you replace the rows again, writes fail with the code replace-unfinished.
Note:
- If you reference your collection by name in active automation messages, changing the name of the collection will cause references to the previous name to return an empty data set.
- A collection that you upload or send in an API request can be up to 10 MB. A collection that you load from files, with write requests or a sync, can be larger: each file can be up to 500 MB and 1,000,000 rows. Each top-level field in a row can hold up to 10,000 characters. The total size of all collections in your account can't exceed 5 GB. Customer.io rejects a request that would take your account over that limit.
- Type: integercollection
_id requiredThe identifier for a collection.
- Type: array object[]data
An array of data objects that you want to reference in this collection.
- Type: stringdelete
_field max length:255An attribute that marks a row for deletion, like
deleted. When a row in a write request or a synced file sets this attribute totrue, or to the texttrue,1, oryesin any case, Customer.io deletes the row with the same key instead of saving it. Deleting a key that doesn't exist does nothing. Customer.io never keeps a row that this attribute marks. When you create or replace a collection, Customer.io leaves marked rows out. When you set a delete field on an existing collection, Customer.io deletes the rows it already marks. A row that isn't marked keeps the attribute as you sent it. The delete field can't be the same as the key field. Send an empty string to remove it. - Type: stringkey
_field The attribute that holds each row's unique key, like
sku, similar to a primary key in a database table. Set a key field to add, change, delete, or read individual rows without replacing the whole collection. Each row needs a unique, non-empty string or number in this attribute, up to 1,024 bytes. - Type: stringname
The name of the collection. This is how you'll reference your collection in messages—
{{collection_name.data-property}}.
- application/json
- application/json
- 400
Your request was malformed.
- 409
An earlier replacement stopped partway, or another change got in first. Replace the collection's rows again.
- 422
Customer.io couldn't accept the change. For example,
delete_fieldcan't be the same askey_field. - application/json
{
"data": [
{
"eventName": "christmas",
"eventDate": {},
"presents": {
"something_you_want": "toys",
"something_you_need": "socks",
"total": 2
}
},
{
"eventName": "birthday",
"eventDate": {},
"presents": {
"something_you_want": "video games",
"something_you_need": "books",
"total": 2
}
}
],
"name": "events"
}
{
"collection": {
"bytes": 296,
"created_at": 1552341937,
"delete_field": "deleted",
"id": 1,
"key_field": "sku",
"name": "upcoming events",
"rows": 2,
"schema": [
"eventDate",
"eventName",
"presents"
],
"updated_at": 1552341937
}
}Customer.io updated the collection. Customer.io also responds with a 200 when you send a key field or delete field that's already set.