onesignal

How do I send a push notification via the OneSignal API?


When I try to send a push notification via the OneSignal API, I get this error: All included players are not subscribed. I can see my device subscribed on the OneSignal subscription records page, and when I send a notification via the OneSignal dashboard, it works. The device gets the push notification. But when I try to send a push notification via the API, it fails.

I'm sending a POST request to https://onesignal.com/api/v1/notifications.

I have the Basic Authorization header set, and that's working or I would be getting a different error.

I have also verified that the app ID is correct.

Here is my request body:

{
    "app_id": "[MY_APP_ID]",
    "included_segments": [
        "All Subscriptions"
    ],
    "target_channel": "push",
    "contents": {
        "en": "TEST"
    }
}

I have also tried Total Subscriptions and All in the included_segments array, but neither of those work either.

Initially, I was trying to send notifications to specific external IDs using include_alises instead of included_segments like so:

"include_aliases": {
     "external_id": [
         "[THE_EXTERNAL_ID]"
     ]
},

But that fails with the same error.

I've also tried targeting by subscription ID using include_subscription_ids, but that also fails with the same error.

What am I missing?


Solution

  • so the question got resolved in the comments itself, still adding the answer for.. reasons.

    the solution: OneSignal uses the "REST API Key" for notifications, not the "API Key". Mixing them up would cause something like this to happen