PHP code example of sendpulse / market-rest-api
1. Go to this page and download the library: Download sendpulse/market-rest-api library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sendpulse / market-rest-api example snippets
endpulse\MarketRestApi\Client;
use Sendpulse\MarketRestApi\Storage\FileStorage;
use Sendpulse\MarketRestApi\Exception\ClientException;
$appId = '9b0f2f98-d75f-4562-887e-2b79bc8a1eee';
$appSecret = '0d028163-9c84-40e4-8508-f4927badf735';
$requestParamCode = '5869d2b87b132aa1372242f223e5381e'; //get code into request
/**
* Get client credentials by login request
* @link https://sendpulse.com/knowledge-base/app-directory/developers/login-flow
*/
try {
$userCredentials = (new Client())
->getClientCredentialsByCode($requestParamCode, $appId, $appSecret);
var_dump($userCredentials);
} catch (ClientException $e) {
var_dump([
'message' => $e->getMessage(),
'httpCode' => $e->getCode(),
'responseBody' => $e->getResponseBody(),
'headers' => $e->getHeaders(),
'curlErrors' => $e->getCurlErrors(),
]);
}
/**
* List user addressbooks by client credentials
* @link https://sendpulse.ua/ru/integrations/api/bulk-email#lists
*/
try {
$clientId = '';
$clientSecret = '';
$addressbooks = (new Client())
->setClientCredentials($clientId, $clientSecret, new FileStorage(''))
->get('addressbooks', [], true);
var_dump($addressbooks);
} catch (ClientException $e) {
var_dump([
'message' => $e->getMessage(),
'httpCode' => $e->getCode(),
'responseBody' => $e->getResponseBody(),
'headers' => $e->getHeaders(),
'curlErrors' => $e->getCurlErrors(),
]);
}
/**
* List user addressbooks by one flow
* @link https://sendpulse.ua/ru/integrations/api/bulk-email#lists
*/
try {
$client = new Client();
$userCredentials = $client->getClientCredentialsByCode($requestParamCode, $appId, $appSecret);
$addressbooks = $client->setClientCredentials(
$userCredentials['client_id'],
$userCredentials['client_secret'],
new FileStorage('')
)->get('addressbooks', [], true);
var_dump($addressbooks);
} catch (ClientException $e) {
var_dump([
'message' => $e->getMessage(),
'httpCode' => $e->getCode(),
'responseBody' => $e->getResponseBody(),
'headers' => $e->getHeaders(),
'curlErrors' => $e->getCurlErrors(),
]);
}