#Custom API hooks examples?
13 messages · Page 1 of 1 (latest)
I have a couple of extensions available making use of hooks but not sure how useful those will be for your usecase. Im not completely sure what you mean with "I need to add more information to the update and delete events" but there are examples in the docs on how to listen for the update/delete events and for fetching extra information needed to take action when such events get fired
Thanks, I did read this https://docs.directus.io/extensions/hooks.html but for me it's not enough to quite get it.
"I need to add more information to the update and delete events" = more than just event/payload/keys/collection
A guide on how to build custom hooks in Directus.
You can fetch extra data as needed in the event handler but you cannot add extra data for other listeners to the event (although with a filter you can manipulate the incoming data before it gets saved to the database)
for example, can I change the "keys" to values of another field than the primary db key?
With the primary key you can fetch any field you desire 🙂
@lusty trout I’d be very interested to see more examples of hooks. I’m working on a bunch and even if not the same use case I’d find it really helpful just in terms of scaffolding
Got a couple public and some more in the works 😉 https://github.com/br41nslug?tab=repositories
Awesome thanks @lusty trout !!!
unless the event is that the item was just deleted*
(*then of course I can retrieve it from the last but one revision, but since i happen to need the very last revision as well, this makes further batch operations all but impossible. if I had the relevant data in the event then I wouldn't need to query the DB for something that's no longer there)
indeed there you would need a filter instead of action so ur code runs before the item gets deleted
not with the admin interface, where a filter prevents the deleting altogether