1. Go to this page and download the library: Download sendpulse/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 / rest-api example snippets
use Sendpulse\RestApi\Client;
$client = new Client(apiKey: 'YOUR_API_KEY');
$client = new Client(
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
);
use Sendpulse\RestApi\Exception\AuthException;
use Sendpulse\RestApi\Exception\ForbiddenException;
use Sendpulse\RestApi\Exception\RateLimitException;
use Sendpulse\RestApi\Exception\ApiException;
use Sendpulse\RestApi\Exception\NetworkException;
use Sendpulse\RestApi\Exception\ProtocolException;
try {
$campaigns = $client->emailService()->campaigns()->getCampaigns();
} catch (AuthException $e) {
// 401 — invalid or expired credentials
} catch (ForbiddenException $e) {
// 403 — tariff or permission restriction
} catch (RateLimitException $e) {
// 429 — back off and retry
} catch (ApiException $e) {
echo $e->httpStatus; // other 4xx / 5xx
echo $e->rawBody;
} catch (ProtocolException $e) {
// response received but could not be parsed (malformed JSON from API)
} catch (NetworkException $e) {
// curl / transport error
}
use Sendpulse\RestApi\Http\Adapter\Psr18Adapter;
$client = new Client(
apiKey: 'key',
httpClient: new Psr18Adapter(
client: $yourPsr18Client,
requestFactory: $requestFactory,
streamFactory: $streamFactory,
),
);
use Sendpulse\RestApi\Token\Psr16TokenStorage;
use Sendpulse\RestApi\Token\InMemoryTokenStorage;
// PSR-16 cache (e.g. Symfony Cache, Laravel Cache)
$storage = new Psr16TokenStorage($psr16Cache);
// In-memory (tokens lost on process exit)
$storage = new InMemoryTokenStorage();
$client = new Client(
clientId: 'id',
clientSecret: 'secret',
tokenStorage: $storage,
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.