Start a new topic

Accessing Endpoint from Collection Hook

I can't find an example of accessing a Custom Endpoint from within a Collection Hook. The HTML5 guides show that Endpoints are accessed via the Kinvey.execute method. In Business Logic there is no Kinvey object.

So, how can I access a custom endpoint from within a pre/post collection hook?

You would have to make a REST call to it -

Be careful not to make a cycle, as your backend will be blacklisted (denied access to BL for 1hr).

Looking at the docs for REST API, I see that I can post to the End Point. So, I played around in the API console and was able to successfully hit my endpoint.

However.... This is not really a good solution. the POST requires 2 critical things. The first is 'authorization'. The second is 'appKey'. In my collection hook, I could hardcode these values in. However, it will all fail when I push my code to production. Right now, I'm in the "development" environment. So, the 'authorization' and 'appKey' are for development. If I hardcode them into my collection hook, they will not work when I go to production.

Actually, they MIGHT work, but the PRODUCTION collection hook will be querying the DEVELOPMENT endpoint. This is a recipe for disaster.

So.. I hope Kinvey has a better solution.
Ivan - You must have answered while I was typing my "answer". Please see my issues with using a REST call to it.
The appKey you can dynamically get from

For Authorization you have two options - just "forward" the incoming authorization header, in which case the endpoint will be called with the same credentials as the hook, or just do basic auth with the appKey:masterSecret. (BasicAuth doc -

I guess we could provide wrappers to make this dead simple, but it doesn't feel too difficult?


I've struggled with this for 2 days. I can't come up with a onPreSave collection hook that calls my custom End point. See here.

If you've got a sample, of something that works, that would be amazingly useful.


Consider this closed. See
Login or Signup to post a comment