Page 1 of 1

Not able to create an API call in php

Posted: 22. Mar 2020, 17:25
by albertlindeboom
Hi,

I haven't managed to create a successfull API call in PHP, i tried a number of variations.
My connection is secure, can anyone point me in the right direction?

Code: Select all

<?php
$message= 'hi'
$ch = curl_init();
$data = array(
	'm' => urldecode($message),
	'k' => xxxxx
);
$postString = http_build_query($data, '', '&');
curl_setopt($ch, CURLOPT_URL, 'https://www.pushsafer.com/api' );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false );
$response = curl_exec($ch);
curl_close($ch);
?>

Re: Not able to create an API call in php

Posted: 22. Mar 2020, 20:19
by admin
Hi,

do you get any error from your script or do you get a response from the pushsafer server?

You script have some errors!
Here oyu will find a correct one in sectipn PHP (CURL)

https://www.pushsafer.com/en/pushapi

Kevin

Re: Not able to create an API call in php

Posted: 5. Apr 2020, 09:36
by albertlindeboom
Just managed to create a messege. Overlooked on variable.

Re: Not able to create an API call in php

Posted: 5. Apr 2020, 10:32
by admin
your server or hosting package has installed the curllib use this:

Code: Select all

<?php
$ch = curl_init();
$data = array(
	't' => urldecode('Your title'),
	'm' => urldecode('Your message'),
	's' => '1',
	'v' => '1',
	'i' => '1',
	'c' => '#FF0000',
	'd' => '',
	'k' => 'your privatekey'
);
$postString = http_build_query($data, '', '&');
curl_setopt($ch, CURLOPT_URL, 'https://www.pushsafer.com/api' );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false );
$response = curl_exec($ch);
curl_close($ch);
?>
if not use this:

Code: Select all

<?php
$url = 'https://www.pushsafer.com/api';
$data = array(
	't' => urldecode('your title'),
	'm' => urldecode('your message'),
	's' => '1',
	'v' => '1',
	'i' => '1',
	'c' => '#FF0000',
	'd' => '',
	'k' => 'your privatekey'
);
$options = array(
	'http' => array(
		'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
		'method'  => 'POST',
		'content' => http_build_query($data)
	)
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
?>

Re: Not able to create an API call in php

Posted: 5. Apr 2020, 10:33
by admin
albertlindeboom wrote:
5. Apr 2020, 09:36
Just managed to create a messege. Overlooked on variable.
OK, great