# Getting an error from Ionic Push API when trying to send a push notification

**URL:** <https://forum.ionicframework.com/t/getting-an-error-from-ionic-push-api-when-trying-to-send-a-push-notification/27617>\
**Category:** ionic-v1\
**Created:** [July 3, 2015, 11:18am UTC](https://forum.ionicframework.com/t/getting-an-error-from-ionic-push-api-when-trying-to-send-a-push-notification/27617 "2015-07-03T11:18:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![quickivent](https://avatars.discourse-cdn.com/v4/letter/q/8baadc/32.png) [@quickivent](https://forum.ionicframework.com/u/quickivent)\
**Post date:** [July 3, 2015, 11:18am UTC](https://forum.ionicframework.com/t/getting-an-error-from-ionic-push-api-when-trying-to-send-a-push-notification/27617/1 "2015-07-03T11:18:40Z")

</div>

Hi,  
I am trying to send a push notification through the Push API, as explained here: [http://docs.ionic.io/v1.0/docs/push-sending-push](http://docs.ionic.io/v1.0/docs/push-sending-push)

But the response I’m getting is always this:  
{  
“result”: “error”,  
“message”: “Either a single or list of tokens is required”  
}

My payload is this:  
{  
“tokens”:[  
“b284a6f7545368d2d3f753263e3e2f2b7795be5263ed7c95017f628730edeaad”,  
“d609f7cba82fdd0a568d5ada649cddc5ebb65f08e7fc72599d8d47390bfc0f20”  
],  
“notification”:{  
“alert”:“Hello World!”,  
“ios”:{  
“badge”:1,  
“sound”:“ping.aiff”,  
“expiry”: 1423238641,  
“priority”: 10,  
“contentAvailable”: true,  
“payload”:{  
“key1”:“value”,  
“key2”:“value”  
}  
},  
“android”:{  
“collapseKey”:“foo”,  
“delayWhileIdle”:true,  
“timeToLive”:300,  
“payload”:{  
“key1”:“value”,  
“key2”:“value”  
}  
}  
}  
}

I tried many variations: passing a single string instead of an array, passing real and fake tokens, passing dev and android tokens, passing just one token in the array, with out without the optional sections of “android” and “ios”.

I always get the error above.

Any ideas why?

---

<div class="post-metadata">

**Author:** ![powerofpeaceproject](https://avatars.discourse-cdn.com/v4/letter/p/3d9bf3/32.png) [@powerofpeaceproject](https://forum.ionicframework.com/u/powerofpeaceproject)\
**Post date:** [July 3, 2015, 8:55pm UTC](https://forum.ionicframework.com/t/getting-an-error-from-ionic-push-api-when-trying-to-send-a-push-notification/27617/2 "2015-07-03T20:55:36Z")

</div>

I am having the same issue, and I am using a script that worked for me previously. Perhaps something has recently broken?

---

<div class="post-metadata">

**Author:** ![obenavidez](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/obenavidez/32/89112_2.png) [@obenavidez](https://forum.ionicframework.com/u/obenavidez)\
**Post date:** [July 3, 2015, 10:20pm UTC](https://forum.ionicframework.com/t/getting-an-error-from-ionic-push-api-when-trying-to-send-a-push-notification/27617/3 "2015-07-03T22:20:53Z")

</div>

Hi, i’m using the Advanced Rest Client.

And works perfect to me

url: [https://push.ionic.io/api/v1/push](https://push.ionic.io/api/v1/push)  
headers:

```
X-Ionic-Application-Id: YOUR_APP_ID
Authorization: Basic YOUR_PRIVATE_API_KEY-BASE64ENCODED

```

payload:

```
{
  "tokens":[
    "DEV-cf6b7ff1-fc8c-436e-a5f7-a6bd8542699c",
    "DEV-92824417-0d4f-4f25-8027-52d12fbee431"
  ],
  "notification":{
    "alert":"Hello World!",
    "ios":{
      "badge":1,
      "sound":"ping.aiff",
      "expiry": 1423238641,
      "priority": 10,
      "contentAvailable": true,
      "payload":{
        "key1":"value",
        "key2":"value"
      }
    },
    "android":{
      "collapseKey":"foo",
      "delayWhileIdle":true,
      "timeToLive":300,
      "payload":{
        "key1":"value",
        "key2":"value"
      }
    }
  }
}

```

test this, if you need i have a php script who works perfect to me.

---

<div class="post-metadata">

**Author:** ![desBiz](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@desBiz](https://forum.ionicframework.com/u/desBiz)\
**Post date:** [September 3, 2015, 7:47am UTC](https://forum.ionicframework.com/t/getting-an-error-from-ionic-push-api-when-trying-to-send-a-push-notification/27617/4 "2015-09-03T07:47:11Z")

</div>

Hi Obenavidez,

May i have the PHP script that you are using to push notification which works for you?

Best Regards,  
Desmond

---

<div class="post-metadata">

**Author:** ![obenavidez](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/obenavidez/32/89112_2.png) [@obenavidez](https://forum.ionicframework.com/u/obenavidez)\
**Post date:** [September 25, 2015, 7:23pm UTC](https://forum.ionicframework.com/t/getting-an-error-from-ionic-push-api-when-trying-to-send-a-push-notification/27617/5 "2015-09-25T19:23:15Z")

</div>

sorry desBiz for the late this is my script

```
<?php
include("../conexion/conexion.inc.php");
$link = Conectarse();
error_reporting(0);

$sql = "select token_push from mo_usuario where estado = '1'";

$resultado=mysql_query($sql);
                
if ( !$resultado ) 
    { 
        exit( "Error en la consulta SQL" ); 
    }

$data=array();
$i=0;
while($row=mysql_fetch_array($resultado, MYSQL_ASSOC)){    
$data[] = $row['token_push'];
}

$msg = "Nuevas Promociones y Eventos";//$_GET['msg'];
$user = "MoveOn";//$_GET['user'];

$device_token=$data;

$url = 'https://push.ionic.io/api/v1/push';

$data = array(
                  'tokens' => $device_token, 
                  'notification' => array('alert' => ''.$user.': '.$msg),      
                  );
echo json_encode($data);
$content = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_USERPWD, "public-key-of-your-app" . ":" );  
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'X-Ionic-Application-Id: your-id-ionic-app' 
));
$result = curl_exec($ch);
//var_dump($result);
curl_close($ch);

?>
```

---

<div class="post-metadata">

**Author:** ![benjieward](https://avatars.discourse-cdn.com/v4/letter/b/a5b964/32.png) [@benjieward](https://forum.ionicframework.com/u/benjieward)\
**Post date:** [October 16, 2015, 8:17am UTC](https://forum.ionicframework.com/t/getting-an-error-from-ionic-push-api-when-trying-to-send-a-push-notification/27617/6 "2015-10-16T08:17:00Z")

</div>

I had a similar problem when creating a request in C# using the RestSharp library.

This worked for me:

`
var privateKey = "xxxx";
            var tokens = new String[] { "yyyy", "yyyy" };
            var appId = "zzzz";
```
        dynamic jsonPostData = new
        {
            tokens = tokens,
            production = false,
            notification = new
            {
                alert = "Hello world",
                title = "test",
            }
        };

        var client = new RestClient("https://push.ionic.io/api/v1");
        client.Authenticator = new HttpBasicAuthenticator(privateKey, "");

        var request = new RestRequest("push", Method.POST);

        request.AddJsonBody(jsonPostData);

        request.AddHeader("Content-Type", "application/json");
        request.AddHeader("X-Ionic-Application-Id", appId);

        var response = client.Execute(request);
        var content = response.Content;

```
`

The request has 5 parameters:

{application/json={“tokens”:[“yyyy”,“yyyy”],“production”:false,“notification”:{“alert”:“Hello world”,“title”:“test”}}}  
{Content-Type=application/json}  
{X-Ionic-Application-Id=zzzz}  
{Authorization=Basic xxxx-encodedbase64}  
{Accept=application/json, application/xml, text/json, text/x-json, text/javascript, text/xml}
