Sending Notification to Specific User with Onesignal

I was wondering if I can send a notification to specific user when he is not on the app.
do you explanation here about per user notification work when the user is not active?

Yes the push messages work even when the user does not have the app running.

Thank you for your reply.
I have another question, let’s say that I make it work and I want to send a notification to that specific user, where do I do it, and how? will I be able to do this in the OneSignal website?
sorry if question was too much. I will appreciate any answer.

Thanks

There are probably a number of approaches, but here is mine.

  1. When a user logs into my app, I create a user profile in firebase which includes the Firebase UserID and the One Signal User ID (among other properties).
  2. When User A wants to send a push message to User B, my app gets the User B One Signal User ID from Firebase. User A’s application instance sends a push message to User B’s One Signal User ID.

I hope that helps

Happy Thunking!

1 Like

Hi, I’m new here, this information really helped me a lot. I tested my application using these blocks and it works in my application.
Thank you so much.

I have the blocks setup properly but when I click the button the push notification is not sent if the app is closed or if the phone is locked. I need to rephrase that, the notification is sent, but my phone does not show me the notification from outside the app or if the phone is locked, I won’t get the notification until I open up the app again, then it just displays similar to an alert warning.
I checked onesignal and I see that the notifications are in fact going through properly, it says “delivered” in green under the status column.

What am I doing wrong?

could this be an issue with your phone settings?

I thought about that too but I get other push notifications regularly

1 Like

Does anyone have a solution on sending notification for more than 30 days in the future. One signal does not support that.

A solution incorporating airtable and integromat may work for you @funhall

App sends entry to airtable for when to send a message to a particular userID

Integromat checks it weekly for new entries

When new entry is in the appropriate time frame → create OneSignal push message

1 Like

This all looks a little flaky. I tried the solution proposed by @jacob1 and couldn’t get that to work. I got error messages about invalid character at line 1 column 3. I tried the solution proposed by @drted and couldnt get that to send anything. So I combined the two methods.
If you are having issues getting this to work try this approach.

  1. In the query parameters of your web_api component add parameter app_id. in the value field add your onesignal api id

  2. In the headers section add two items:-

         (i) Authorisation.  In the value field enter the word Basic followed by a space then paste your 
         REST API KEY.  Note I spelt authorisation with an "s".  I dont know if that is important or if 
         being in the UK, spellcheck did it.
    
        (ii) Content-Type.  In the value field enter application/json.
    

Then in the blocks section I have this.


Also of note, the app variable PushToDrivers is a list of driver pushID’s from our database. We check this list each time we send a notification to see who is logged on so we only send to drivers who are working.

This approach appears to work so give it a go if you are stuck.

Cheers

2 Likes

I hv got it!

Check this out

I have tried to check the above solutions but for some reason, it doesn’t work out from my end. I have tried exactly what @rwplummer1yf4f mentioned but nothing.

I have tried to use Postman to check what I get from the request (I get 403 error, and some time it works with error that user is not in the Subscribed Users, although I use include_external_user_ids).

If someone can help out to check if I can use the Onesignal API for notifications or not as it is a must feature in the app that I am building.

Resolved after contacting OneSignal support when I used the following URL:

api.onesignal.com/v1/notifications

Here is their reply for the 403 and 443 errors that I got:
"

For sending notifications:
Use port: 443
We recommend whitelisting Previous link

Previous link is routed through cloudflare servers. If you need to whitelist a range of IP address, you use this list however it’s not going to be the full list: https://www.cloudflare.com/ips/

Depending on how your network is setup, set your DNS to allow 1st Link to resolve.

For receiving notifications:
If your organization has a firewall that restricts the traffic to or from the Internet, you need to configure it to allow connectivity with FCM in order for your Firebase Cloud Messaging client apps to receive messages. The ports to open are: 5228, 5229, and 5230. FCM typically only uses 5228, but it sometimes uses 5229 and 5230. FCM doesn’t provide specific IPs, so you should allow your firewall to accept outgoing connections to all IP addresses contained in the IP blocks listed in Google’s ASN of 15169. > From the “Firewall” note: FCM options

Let us know if you need more help.
"
Sorry I couldn’t include all links because Thunkable reply doesn’t allow me for more than 2 links in a reply

3 Likes

That’s useful information and good to know. Thanks.

This does send notifications to all users .Can u plz help

then

Hi Jacob,

I am trying to create a calendar app where each user can schedule notifications. Is there a way to use this method of sending an individual user a specific notification but at a scheduled time in the future?

Thank you in advance

Hi Guys, today January 20 2024 I made it work with the help of the OneSignal API docs and postman to check the parameters and Headers of the API with the following block result, it works flawlessly!!! I hope it helps!!!

1 Like

Certainly! Here’s the revised text in English:


Tutorial: Sending Push Notifications to Specific Users via REST API in Thunkable

For many months, perhaps years, I struggled to make the Push Notificator work using the REST API method. However, in January 2024, I came across the latest post and decided to give it another try.

After numerous unsuccessful attempts, I saw a glimmer of hope when revisiting the provided guidance. The key lay in the API call header, where I previously made mistakes. Initially, I was only including the “Authorization” and “Content-Type” headers. However, following a recent suggestion here, I realized that it was also necessary to add the “external_id” header to the request.

Although I didn’t fully understand at the time, with the help of some API call responses, I soon identified why the previous attempts had failed. I removed the “accept” header and left only the following headers:

  • Authorization: Bearer (your API key)
  • Content-Type: application/json
  • external_id: GetmypushId

I also understood that to send a push notification to a specific user, it was necessary to declare it as a list, even if it was only a single user to be notified. This is because when creating a JSON object, as it is in a list block, it is interpreted as an array , indicating the possibility of having numerous items inside.

By configuring the blocks in this way, I finally managed to make the API call and notify the specific user, even in test mode, without the need to download and install the application on the phone.

I sincerely hope that this approach resolves the problems of many other developers, just as it resolved mine.

Happy Thunking!

Example API Call in JSON:

{
  "app_id": "your_app_id",
  "include_player_ids": ["user_id"],
  "contents": {"en": "Your notification message here"},
  "headings": {"en": "Notification Title"}
}

I hope this text better reflects your experience and is helpful to the Thunkable community! If you need anything else or have any questions, feel free to ask.