Created
December 10, 2018 14:47
-
-
Save Adoonq/c7b8eea3b769251bf872e78c31af0969 to your computer and use it in GitHub Desktop.
Sendpulse add email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$access_data = array( | |
'grant_type' => 'client_credentials', | |
'client_id' => '478f545c4124c737ce7e05a2534c1342', | |
'client_secret' => 'c034ff43f6b298b2d0bcf40ef7ca9d46', | |
); | |
$token = sendRequest('oauth/access_token', $access_data, false); | |
$bookID = 2151674; | |
$data = array( | |
'emails' => array( | |
'email' => $hook->getValue('user_email') | |
) | |
); | |
$requestResult = sendRequest('addressbooks/' . $bookID . '/emails', $data, true, $token->access_token); | |
if ($requestResult->result) return true; | |
else return false; | |
function sendRequest($path, $data = array(), $useToken = true, $token = false) { | |
$url = 'https://api.sendpulse.com'.'/'.$path; | |
$curl = curl_init(); | |
if ($useToken) { | |
$headers = array('Authorization: Bearer ' . $token); | |
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); | |
} | |
curl_setopt($curl, CURLOPT_POST, count($data)); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); | |
curl_setopt($curl, CURLOPT_URL, $url); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl, CURLOPT_HEADER, true); | |
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15); | |
curl_setopt($curl, CURLOPT_TIMEOUT, 15); | |
$response = curl_exec($curl); | |
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); | |
$headerCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); | |
$responseBody = substr($response, $header_size); | |
curl_close($curl); | |
return json_decode($responseBody); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment