PATCH call in Entry.publish webhook sets entry state to "changed"

Hello!

We are writing a backend app for the Marketplace and have an infinite loop problem:

Our backend app, which is (subscribed to the Entry.publish event), makes a CMA PATCH request very similar to this one, saving some data into a single field in the entry.

The PATCH CMA JS code is heavily based on the fetch code from the contentful/apps example here.

During the PATCH request the field is updated OK, but the entry status (visible in the Sidebar) moves from “published” to “changed” when the field is updated.

I have tried making a second PUT request in our backend app to the /published endpoint, but this causes an infinite loop.

Is there a recommended way for a backend app/webhook to listen to the Entry.publish event and make changes to a field without setting the published state of the entry to “changed”?

1 Like

I was able to solve this problem by storing the entry id in an external storage. In my case I used redis and so I did not need to store the timestamp but instead set a very short ttl equal to the cool down time. In the endpoint, you can check to see if the entry has already been updated previously and short circuit with a return to prevent the endless loop.

Since I was using Redis, I set a ttl of about 10 seconds to serve as a cool down time. Why do you need a cool down time? If you do not expire the value in Redis, then any subsequent request to update the updated entry will fail because your endpoint will short circuit as it attempts to prevent the endless loop. Why 10 seconds, 10 seconds is within the time frame it takes for Contentful to send another webhook request after your first update and publish event