I have setup an event handler that will trigger a push notification when a table row is updated.
It was working an hour ago, now it is not. I think the listener is buggy.
Could you please check this environment:
App ID: B78A830E-7A03-838E-FF36-46CF57DEF200
Event Handler - afterUpdate on table “Sites”. Only one there.
To test,
- On table “Sites”, go to row where Channel is “7540.15SPR”. There are only 4 rows in the table.
- Update “TestPushNotification” column, to “red”, “green” or “orange”.
- Check the real-time logger on the event handler.
- Never gets logged, so the listener is broken.
Thanks
How did you test your logic?
Did you use REST console or maybe some curl request ?
In case of “REST console” I can not perform the update if only one column is in the request. In such a case I receive error from your code:
{
“code”: 0,
“message”: “Channel Name must be provided and must be a string.”
}
Request body is:
{
“TestPushNotification”:“red”
}
Hi Oleg,
Are you referring to the Push Notification? I have tested is many ti es and it works great from curl. Use “7540.15SPR” for channel. I will receive the notification on my phone.
Use red, green or orange for TestPushNotification. I think the listener is the problem, the API service.
No, i’m talking about updating record in the table, just as you described in a first post.
Could you show your curl request, please.
You also wrote
I have tested is many ti es and it works great from curl.
And it confused me a little. Are you experiencing the problem now (when you update the table) ?
As I understood handler works during the update operation.
Hi Oleg,
Let me try to clear up the confusion.
-
I have 2 push notification APIs set up. One of them is targetd to All devices registered to a Channel. Other is targeted to a specific device.
-
The notification’s header contains a color code (red, green or orange). The mobile app receiving the notification performs some actions depending on the color.
-
This notification service works fine. Here is a curl script I used:
curl -X “POST” “https://api.backendless.com/B78A830E-7A03-838E-FF36-46CF57DEF200/BC28F1C3-6611-4633-A83C-59324EDC8B1D/services/PushAlert/notifyChannel”
-H ‘Content-Type: application/json’
-H ‘Accept: application/json’
-d $’{
“channel”: “7540.15SPR”,
“color”: “red”
}’
-
Now, I want trigger the notification when a row is updated on a table. The table is “Sites”. I am updating the field “TestPushNotification” with different color codes. Doing this manually on the table for now. Will be automated later as per the business logic.
-
So I set up an event handler (“afterUpdate”) to listen to updates on “Sites”. When updated, the handler should pick the “Channel” and “TestPushNotification” from that row and fire off a notification to that channel.
-
However, this is not working when I update the “TestPushNotification” field . I set up a logger in the event handler, and I don’t see any logs either. So the handler is not getting triggered when I update the row. I am using the row with Channel = “7540.15SPR”.
So that is the problem. I had it working a few times before, but not anymore.
Please, provide curl api request, which you make to the Backendless server, which changes the row in the table Sites (and which should be a reason for the event handler calling – beforeUpdate, afterUpdate).
Oh. I am not using curl for that. I am doing it manually on that table.
But it is not an api call!
So, that is the reason.
So only an API call trigger that? That seems weird. Can I update that table through UI builder logic and make it work?
Yes, only API cal is a trigger.
Nothing weird. It is intended to separate some development actions and the real calls.
Thanks Oleg. That was helpful