Collection list not updating after adding item via API

Reproduction
This bug is a bit hard to reproduce without setting up an entire new site with API access, because I can’t try it out on my client’s live site.

Behaviour
The site has a collection list that only lists the latest press release, from a collection of multiple press releases. The collection list in question is limited to 1 item and sorted Newest to Oldest. When publishing to the collection via the API, the collection list on the homepage (the left box all the way on the bottom of the page) does not show the latest collection item. However, when going to IR->Press Releases, where all items from the same collection are displayed, it sits there at the top.

The only way to make the collection list on the first page to update is to make a dummy change to some part of the site and then publish it.


Here is my site Read-Only link

Just to be sure, are you publishing the website after sending the new item through the api ?

https://developers.webflow.com/#publish-site

I’m adding the item with a { live: true }, which makes it show up in all expected places on the live site, except for the one one the start page. Is there a difference between setting it as live and calling a publish command on the API?

Take a look at this paragraph:

image

What I recommend you to do is make the your server-side code (that updates the CMS item ) run asynchronously. Whenever the update is done, call the endpoint that publishes your website afterwards.

You should test it out since it’s a fairly simple adjustment. Let me know how it goes :slight_smile:

I’ve actually run into an issue related to that before, where we had different versions of the site on two different domains. However, the issue I’m describing is that every instance of the collection list is correct, except for one. Which leads me to think there is a bug on the other end, considering everything is published correctly on all other pages.

Yes, I understand what you mean and it’s definitely a weird behavior for sure. I was just thinking of a quick fix for you, given what you said:

Absolutely a fix for now — thank you!

My current code for adding an item is this:

const webflowItem = webflow.createItem({
      collectionId: PRM_COLLECTION_ID,
      fields: {
        'name': title,
       // [a bunch of data]
        '_archived': false,
        '_draft': false
      }
    }, { live: true });

Do you think I would have to restructure it completely to allow for a publish call after adding the item?

Not really. You just need to implement some sort of callback to it. Here’s how it would look:

const webflowItem = webflow.createItem({
      collectionId: PRM_COLLECTION_ID,
      fields: {
        'name': title,
       // [a bunch of data]
        '_archived': false,
        '_draft': false
      }
    }, { live: true });

webflowItem.then(i => {
const published = webflow.publishSite({ siteId: 'YOURSITEID', domains: ['test-api-domain.com'] });
})

The domains array needs to be an array of the domains that you want to publish your changes

Ah! I actually wrote something similar for another part of the server. Thank you so much for taking the time!

I’m more designer than programmer really, but oh boy do you increase the possibilities by learning how to work with the API.

Thanks again!

1 Like

No problem at all my man! It’s always a pleasure! And heck yes, I love the full-stack! I’m no designer myself, so I better be versed with the development part of things!

I’m glad that I could be of help! Feel free to reach out at any time!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.