Idempotent CMS item creation

Right now, when you create a CMS item, you provide a slug to identify it. Using the Create Collection Item api, if your slug does not exist, it creates with the slug you've provided. However, if the slug does exist already, a random string is appended to the slug you've provided.


> curl --request POST \

--url https://api.webflow.com/v2/collections/coll-id/items \

--header 'accept: application/json' \

--header 'authorization: Bearer token' \

--header 'content-type: application/json' \

--data '

{

"isArchived": false,

"isDraft": false,

"fieldData": {

"field-1": "example",

"name": "Example 1",

"slug": "example-1"

}

}

'

{"id":"...","cmsLocaleId":"...","lastPublished":null,"lastUpdated":"2023-12-06T19:49:17.262Z","createdOn":"2023-12-06T19:49:17.262Z","isArchived":false,"isDraft":false,"fieldData":{"field-1":"example","name":"Example 1","slug":"example-1"}}

If you send it again... you get mostly the same thing, but a new slug.

{"id":"...","cmsLocaleId":"...","lastPublished":null,"lastUpdated":"2023-12-06T19:49:25.273Z","createdOn":"2023-12-06T19:49:25.273Z","isArchived":false,"isDraft":false,"fieldData":{"field-1":"example","name":"Example 1","slug":"example-1-e9f6b"}}


This would be fine if there were ways to work around this. Get Collection Item requires knowing the item ID and can't be queried by slug. The only way to then find the item ID of a slug you want to use is to then page through List Collection Items. And if there are thousands of CMS items, there is no practical way to know early on if you are able to upload a duplicate CMS item.

So, making this API idempotent or providing a flag to either fail or upsert if a slug already exists would be great!

  • Renning
  • Dec 6 2023