Can not create Event Handler to return custom response

I have a Todos object and I create an Event Handler for “After Find” to return custom response:

Which is expexted to return response like this:
image

But it doesn’t work. It still return default response:

Hi @irwancheung

Event Handlers will just run the additional function that you created. It won’t do any changes to your response.

I think you are really looking to use the Codeless API Service. There you can the specific route and transform your response from the application.

There is a sample for your Codeless API Service:

Regards, Denys

But it works with Event Handler for User Service.


I tried the workaround by creating api service which called the Data Service API

where the Data service API has event handlers to return only specific properties which work if called directly:

But the Event handler doesnt work if called by API Service:

@irwancheung
We will investigate the current issue. The internal ticket (BKNDLSS-24220) was created.

Regards, Denys

@irwancheung , what is your application ID, I’d like to take a look at the configuration of the event handler.

@mark-piller it is B4F92BD3-34B5-C368-FFA7-78380524F500

@irwancheung, I modified a permission for the Todos table as shown below:

Could you please try it again?

Regards,
Mark

The event handlers still doesn’t work if data service is called via api service.

Do you send the “user-token” header with the invocation request?

Yes, I did. I tried using beforeFind to return custom error.


It worked well when I invoked its Data Service API in Postman.

But when I invoked the API using custom service

It still returned the objects. The event listener didn’t work.

If the call is performing from the BL the subsequent calls to the BL won’t occur in order to eliminate cyclic calling.
I would recommend to move the common logic to the separate method and call it from both the custom service and from any handler.

1 Like

Hello @irwancheung,

If we back to original question, then you should wrap your object with array, because when you try to find the result should be an array of object, and you return a single object.