PHP code example of notideus / notideus-php

1. Go to this page and download the library: Download notideus/notideus-php 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/ */

    

notideus / notideus-php example snippets




use Notideus\NotideusClient;

$notideus = new NotideusClient(getenv('NOTIDEUS_API_KEY'));

$email = $notideus->emails()->send([
    'from' => 'Acme Inc <[email protected]>',
    'to' => ['[email protected]'],
    'subject' => 'Welcome',
    'html' => '<p>Hi {{name}}</p>',
    'variables' => ['name' => 'Jane'],
    'tags' => ['welcome'],
    'idempotency_key' => 'req-123',
]);

new NotideusClient(?string $apiKey = null, array $options = []);

$notideus->emails()->send(['from', 'to', 'subject', 'html?', 'text?', 'template_id?', 'variables?', 'tags?', 'headers?', 'reply_to?', 'idempotency_key?']);
$notideus->emails()->sendBatch([['from' => …, 'to' => …, …]]); // up to 100

$notideus->whatsapp()->messages()->send([
    'template_id' => 'tpl-1',
    'to' => ['+33612345678'],
    'parameters' => ['body:1' => 'Jane'],
]);
$notideus->whatsapp()->messages()->sendBatch([…]);

$notideus->contacts()->create(['email', 'properties?', 'topic_ids?']);
$notideus->contacts()->get('[email protected]');
$notideus->contacts()->update('[email protected]', ['properties' => ['plan' => 'pro']]);
$notideus->contacts()->delete('[email protected]');
$notideus->contacts()->unsubscribe('[email protected]');
$notideus->contacts()->resubscribe('[email protected]');
$notideus->contacts()->bulk([['email', 'properties?'], …]); // up to 1000

$page = $notideus->contacts()->list(['limit' => 100, 'status' => 'subscribed']);
if (isset($page['next_cursor'])) {
    $next = $notideus->contacts()->list(['cursor' => $page['next_cursor']]);
}

$info = $notideus->unsubscribe()->info($token);
$notideus->unsubscribe()->unsubscribe($token);            // whole contact
$notideus->unsubscribe()->unsubscribe($token, [$topicId]); // specific topics
$notideus->unsubscribe()->preferences($token, [$topicId]); // desired subscribed set

$catalog = $notideus->plans()->list('fr'); // locale optional

use Notideus\NotideusException;

try {
    $notideus->emails()->send([…]);
} catch (NotideusException $e) {
    if ($e->getErrorCode() === 'from_domain_not_verified') { … }
    if ($e->getErrorCode() === 'rate_limited') {
        $e->getRetryAfter(); // seconds to wait
    }
    $e->getStatus(); // HTTP status
}

$results = $notideus->emails()->sendBatch([…]);
foreach ($results as $item) {
    if (isset($item['error'])) {
        error_log($item['index'] . ' ' . $item['error']['code'] . ' ' . $item['error']['message']);
    } else {
        error_log($item['index'] . ' ' . $item['id']);
    }
}

$notideus = new NotideusClient(getenv('NOTIDEUS_API_KEY'), [
    'base_url' => 'http://localhost:8080',
]);
bash
composer