I am sending push notes from a PHP script. They are received twice on all my devices, so this is not a question of a wrong setup in one of my devices. OTOH, if I send a push notice from one of my devices to another, it appears only once. I cannot figure out why this is happening and hope someone else has the right idea. The script looks ok to me.
<?php
$qs = $_SERVER['QUERY_STRING']; // get query string like "bookid=35954441&status=modify"
if ($qs ==""){
$qs = 'no message';
}
date_default_timezone_set('America/Panama');
$today = date('d/m/Y H:i:s',$_SERVER['REQUEST_TIME']);
$data = array();
$data['type'] = 'note';
$data['title'] = 'Aparthotel Boquete - '.$today;
$data['body'] = "· ". str_replace("&"," \n· ",$qs) ;
$json = json_encode($data);
$url="https://api.pushbullet.com/v2/pushes";
$ch=curl_init();
curl_setopt($ch, CURLOPT_POST, 1) ;
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ##################', 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$Json_object = curl_exec($ch); // this is a JSON string
$result = json_decode(curl_exec($ch),true); // creates an associative 2 dimensional array $booking[i]['key'] where i= booking index
curl_close ($ch);
?>
var_dump of the JSON object shows this among other items: ,"created":1674359389.1863782,"modified":1674359389.1906438, This could be a hint. Maybe the push note is created (and sent), and then sent again as "modified"? But why? Is any of the CURL options the cause?
I just found the answer myself after several tests. While the script is executed only once, the CURL call was run a second time when I decoded the result:
Thank you for your hint, ADyson. I am glad I found it fast enough not to waste more people's time. I let it stand anyway, hoping that it may help others to discover similar errors.