Events
Using the webhooks
setting available in netflex, you can make Netflex send you webhooks whenever an entry is created
, updated
or deleted
through the Content API or through Netflexapp. The toolbox adds a standardized endpoint for receiving all these events, in order to abstract this away and expose the webhooks through laravels event system.
Setting up webhooks for a structure
The toolbox registers the route .well-known/netflex/structure-webhooks
when installed. This route can be inserted into the webhooks
config as such
Creating a listener
Registering a listener
You can register event listeners as normal in your EventServiceProvider.
Notice that you have to register Create, Update, and Delete events separately as Laravel does not let you listen to the parent event. If you want, its trivial to write a listener for the super class and just register for each child event as all events have the same functions and fields.
Caching
EntryCreated
and EntryUpdated
will only resolve the underlying entry once, then return the same instance on subsequent calls. It is advised that you do not edit the event as you might break assumptions if there should be/are multiple listeners.
EntryDeleted data
When EntryDeleted is triggered, the entry is already gone, and you can't fetch the entry from the database anymore. We do get the entry as it existed when deleted however, so the event will return a hydrated object based on these data.
For all intents and purposes the event will look like it came from the database, but looking up relationships etc might not work as expected.