Not able to create an API call in php

Pushsafer make it easy and safe to get push-notifications in real time on your Android or Windows mobile device, iPhone, iPad and Desktop!

Mit Pushsafer kann man in Echtzeit, einfach und sicher, Push-Benachrichtigungen auf sein iPhone, iPad, Android oder Windows Gerät sowie auf den Desktop senden lassen!

======================
Google Play
App Store
Windows Store
Homepage
albertlindeboom

Not able to create an API call in php

Postby albertlindeboom » 22. Mar 2020, 17:25

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);
?>

User avatar
admin
Site Admin
Posts: 943
Joined: 1. Dec 2014, 12:41
Location: Germany

Re: Not able to create an API call in php

Postby admin » 22. Mar 2020, 20:19

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
Pushsafer DE: Dir gefällt Service und Support! Dann freuen wir uns auf deine Bewertung!
Pushsafer EN: You like Service and Support! Then we look forward to your review!

Pushsafer.com Website - iOS - Android - Windows 10

albertlindeboom

Re: Not able to create an API call in php

Postby albertlindeboom » 5. Apr 2020, 09:36

Just managed to create a messege. Overlooked on variable.

User avatar
admin
Site Admin
Posts: 943
Joined: 1. Dec 2014, 12:41
Location: Germany

Re: Not able to create an API call in php

Postby admin » 5. Apr 2020, 10:32

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);
?>
Pushsafer DE: Dir gefällt Service und Support! Dann freuen wir uns auf deine Bewertung!
Pushsafer EN: You like Service and Support! Then we look forward to your review!

Pushsafer.com Website - iOS - Android - Windows 10

User avatar
admin
Site Admin
Posts: 943
Joined: 1. Dec 2014, 12:41
Location: Germany

Re: Not able to create an API call in php

Postby admin » 5. Apr 2020, 10:33

albertlindeboom wrote:
5. Apr 2020, 09:36
Just managed to create a messege. Overlooked on variable.
OK, great
Pushsafer DE: Dir gefällt Service und Support! Dann freuen wir uns auf deine Bewertung!
Pushsafer EN: You like Service and Support! Then we look forward to your review!

Pushsafer.com Website - iOS - Android - Windows 10


Who is online

Users browsing this forum: DavidoosMah, Google [Bot] and 35 guests