How can I update a CMS asset through API?

Hi all, I’m looking for help updating a specific asset within a collection item with the CMS API
I’m trying to optimise my site’s performance by changing all the images to webp.
The site is, and my first step is to convert the hero/banner images for 250 articles (posts in the CMS).

I’ve successfully downloaded the ID and image URLs for each item within the collection. I’ve also converted them to webp, so I have a csv of each item ID with the webp url of the image I want to add to each post.

I was looking at the PATCH endpoint and it wasn’t clear how I could update a specific asset within a collection item on the CMS. Does anyone know how to do this?

Ideally I would like to make a (patch?) request with the collection ID, the specific item ID, an ID of the asset I want to update within that specific item, and the new image URL

Welcome @learko :wave:

I’m assuming you’re using the new v2 API and it doesn’t seem to have a good example.

That said, if you look at the legacy v1 API they do have a clue for you:

“Update an existing collection item. To upload a new image set the image URL to the corresponding item’s field.”

Basically, upload your image to a host that is publicly available, then add that public URL to the field in the API. Webflow should grab that public URL, and then re-upload it to it’s own hosting service.

Start with that and see if you can make it work. If not, report back with some examples of what you tried and the errors you received.

1 Like

Very useful – thanks Chris! This is wonderful. All working
I’ve saved hundreds of kilobytes, sometimes even thousands, from hundreds of pages on my site. Should improve loading speeds dramatically.

For anyone trying to do a similar thing and upgrade the images in their CMS to .webp, feel free to use my code below: