Why are my collection hooks not getting called automatically after a save done in my custom endpoint
started a topic
over 3 years ago
So, in my custom endpoint, I am executing a save() statement and inserting data in my collection. However, on testing my custom endpoint, my onPreSave() and onPostsave() collection hooks which I had created for my collection, are not getting called automatically. Only the data gets saved in the collection on testing the custom endpoint, but there is no sign of these collection hooks getting called automatically.
Please help. Any help would be highly appreciated.
Hi Ramesh, collections hooks are only triggered when accessing collections through the REST API (or the libraries, which use the REST API behind the scenes). When you perform a database operation from within your business logic code, you get direct database access, which does not go through any collection hooks.
over 3 years ago
Thanks much for your reply.
Can you please let me know as to what would be the REST API that I would need to use in my custom endpoint in order to insert a record in my collection?
I would also appreciate if you can please give me some sample code or point me to a website where there would be sample code which I could use in my custom endpoint to achieve my objective of inserting JSON formatted data into my collection and also ensuring that my collection hooks are fired simultaneously?
Any help would be highly appreciated.
about 3 years ago
Hey there Ramesh,
The rest API that Gal is referring to has a guide available here: http://devcenter.kinvey.com/rest/guides/datastore . The guide here will help you with your question about using json formatted data as a collection.
As for the other aspect of your question there is some sample code available here: http://devcenter.kinvey.com/rest/reference/business-logic/reference.html#backendcontext-module that should give you a good feel for how you would handle incoming json data in business logic.
Please let me know if you have any other questions.