Answer the question
In order to leave comments, you need to log in
Why is the request not being sent to sendpulse?
https://login.sendpulse.com/manual/rest-api/#add-email
<?php
function get_key(){
$param = array(
'grant_type' => 'client_credentials',
'client_id' => 'bc5dc48863ff967b0ad30b20c37f9c65',
'client_secret' => '92153e52d943bd75c0fe74b3faaf1b02');
$vars = http_build_query($param);
print_r($vars);
$options = array(
'http' => array(
'method' => 'POST', // метод передачи данных
'header' => 'Content-type: application/x-www-form-urlencoded', // заголовок
'content' => $vars, // переменные
)
);
$context = stream_context_create($options);
$result = file_get_contents('https://api.sendpulse.com/oauth/access_token', false, $context);
$result = $result. "";
$array = explode('"', $result);
return $array[3];
}
function set_User($nameUser, $key, $email) {
//$param1 = array(
//'email' => $email
//);
//$serarr = serialize($param1);
//echo $serarr;
$param = array(
'access_token' => $key,
'id'=> '823257',
'name' => $nameUser
);
$vars = http_build_query($param);
$options = array(
'http' => array(
'method' => 'PUT',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $vars,
)
);
$context = stream_context_create($options);
return $result = file_get_contents('https://api.sendpulse.com/addressbooks/{id}', false,
$context);
}
$key = get_key();
echo '<br>';
print_r(set_User($_POST['name'], $key, $_POST['email']));
?>
Answer the question
In order to leave comments, you need to log in
Good afternoon.
The first thing you need to do now is to change API accesses (if they are real). This can be done in your account settings. Be more careful when publishing your codes online. Your personal data can be used by hackers.
Also, I would recommend saving the token received during authorization and using it when you re-request. The token is valid for an hour, there is no need to receive it every time. This will speed up the execution of your scripts.
If you have any questions related to the implementation of certain API methods, you can look at the example from the SendPulse company itself. You can also use a ready-made solution in its entirety so as not to waste time on implementation. Here is the link to the PHP versionhttps://github.com/sendpulse/sendpulse-rest-api-php
You can use the prepared code:
require '../../vendor/autoload.php';
use Sendpulse\RestApi\ApiClient;
use Sendpulse\RestApi\Storage\FileStorage;
define( 'API_USER_ID', $_GET['client-id'] );
define( 'API_SECRET', $_GET['secret-id'] );
define( 'TOKEN_STORAGE', 'file' );
$SPApiProxy = new ApiClient( API_USER_ID, API_SECRET, new FileStorage() );
$emails = array(
array(
'email' => $_GET['email'],
'variables' => array(
'Phone' => $_GET['phone'],
'Name' => $_GET['name'],
)
),
);
$bookID = $_GET['bookID'];
$result = $SPApiProxy->addEmails($bookID,$emails);
$json_result = json_encode($result);
$json_beautified = str_replace(array("{", "}", ","), array("{<br /> ", "<br />}", ",<br /> "), $json_result);
print_r($json_beautified);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question