[OneSignal Plugin] Example of Cancel/Delete of notification?

Forge Component
(13)
Published on 7 May by OutSystems R&D
13 votes
Published on 7 May by OutSystems R&D

Is there any example of how we could cancel or delete a scheduled notifications via the plugin or the API? How can we retrieve the notification's id?

Hi,

The plugin don't has available any action to cancel the notification. But, in the onesignal documentation, you have a REST action to do that.

https://documentation.onesignal.com/reference

You need create a new consume REST API Method, something like that:

I hope this help.

Regards.

Thanks Paulo!

I actually checked this method along with the viewnotification method at the API's documentation but I have not understood how to get the notification's id. I mean the one that I will later need to delete/cancel.

Hi!

Unfortunately, the plugin don't return the notification Id... You need to change that (PushNotifications/PostNotification), and return the notification Id. You need to get this output and save it:

Regards.

It seems that this id is created at the server after the request is sent. I checked the server actions available at the OneSignal API and there seems to be no way to retrieve the notification id before it is created on the server. In the REST API though, there are methods to retrieve all the notifications or a specific notification. So I guess in order to get the id you first need to get all the notifications and then search for the one you need.

If anyone has a better idea, please share :)

UPDATE: Now I got what you meant. I changed the type of response in the post notification method according the result you shared, because the existing was just the JSON representation of an error, so the response output variable didn't include any id. I will update the thread as soon as I am going to make that work as expected.

So now I can get the notification id from the response of the API. I also created the command to cancel a notification according to the API (https://documentation.onesignal.com/reference#cancel-notification).


But there is a problem whenever trying to use this action to cancel a notification. (Though it works perfectly at the testing window, and I can see that the notification is indeed cancelled at OneSignal's admin panel.)
The problem is that I get the following errors:  
( in case the text is not visible : "Error reading JObject from JsonReader. Path ", line 0, position 0." in all three of them. )

And below are the details of the errors above.

I tried to change the Response Format to plain text hoping to bypass the JSON parser, but in the response header there is content-type declaration as JSON, so it still tries to parse the response.

Any ideas how this could be solved? I don't really know what else to try.
Thanks in advance!

Solution

Well , it seems that the problem was created by the OnBeforeRequest action present in the OneSignal API. I consumed the Delete method outside the OneSignal API plug in and it worked perfect.

Solution