I’m using Contentful with Gatsby to generate a static website. I have two webhooks that, when triggered, will build and deploy my static site. One webhook is for Preview and the other for Production.
My question is, what are the best triggers to listen to for each scenario?
My assumption is that for the Production scenario, I only need to listen to “Publish” and “Unpublish”, but I’m not sure. For example, does “Delete” trigger an “Unpublish”? What about “Archive” and “Unarchive”?
For the Preview scenario, can I simply listen to “Save”? Or do I need to listen to something else? For example, will “Delete” trigger a “Save”?
Also, if I don’t select “Content Type”, “Entity” or “Asset” on the left-hand side of the form, will the webhook default to all of those types?
My assumption is that for the Production scenario, I only need to listen to “Publish” and “Unpublish”, but I’m not sure. For example, does “Delete” trigger an “Unpublish”? What about “Archive” and “Unarchive”?
Delete doesn’t trigger Unpublish. I would suggest to explicitly check both events.
For the Preview scenario, can I simply listen to “Save”? Or do I need to listen to something else? For example, will “Delete” trigger a “Save”?
We have two “saves”: Save and Auto-save.
Auto-save gets triggered every 20 seconds if you actively edit an entry in the Web App.
Save gets triggered only if an entry has been updated via Content Management API. Delete won’t trigger Save webhook.
Also, if I don’t select “Content Type”, “Entity” or “Asset” on the left-hand side of the form, will the webhook default to all of those types?
This form appears when only when you check this option Only selected events . So, to turn on webhooks for all events, you can simply check this on All events.
In the end, if you’re planning to actively edit content via Web App, Auto-save would be the option. But in order to not rebuild application every 20 seconds, you can record all Auto-save webhook calls but rebuild only every 10 minutes, for example.
Yep, sounds reasonable.
You’re right- Archive / Unarchive won’t trigger Publish / Unpublish webhooks.
One thing I noticed is that you don’t have neither Save nor Auto-save events on Production. Probably you would want to add one of those. Or am I right, you’re not going to change content but rather mostly Publish/Unpublish on Production environment?
We want our content creators to be able to preview their changes prior to having them appear in production. We were hoping that any changes made would not appear in production until the user explicitly published them. Is that possible?
For example, if Mary makes a change but does NOT publish, then John makes a change and DOES publish, we want John’s change in production, but not Mary’s.
We want our content creators to be able to preview their changes prior to having them appear in production. We were hoping that any changes made would not appear in production until the user explicitly published them. Is that possible?
This is possible by connecting a preview or staging environment to the CPA. So basically how this works is that you have some configuration in your codebase (or environment variables or something) that defines which API to use. For production you use the CDA (only published content) and for the staging environment you then use the CPA.
This means that your “preview environment” then always gets unpublished and/or draft entries using the CPA.
What remains then is the question how often to rebuild the preview environment and this can be timed (every let’s say 5minutes) or reacting to save | auto-save. This depends on how much content changes you’re dealing with (rebuilding every 10s maybe doesn’t make much sense).
For the production environment I wouldn’t recommend triggering on save | auto-save as this environment should be connected to the CDA anyways and only gets new data on publish or similar events.