PHP code example of esauti / esauti-php

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

    

esauti / esauti-php example snippets


use Esauti\EsautiClient;

$client = new EsautiClient(
    'https://your-mautic-host.com/api',
    ['bearer_token' => 'your-api-token'],
    ['timeout' => 30, 'max_retries' => 3]
);

// List contacts
$result = $client->api->contacts()->list(['limit' => 10]);
echo $result['total'];

// Create a contact
$contact = $client->api->contacts()->create([
    'firstname' => 'Jane',
    'lastname'  => 'Doe',
    'email'     => '[email protected]',
]);

// Update a contact
$client->api->contacts()->update($contact['contact']['id'], ['city' => 'Montreal']);

use Esauti\EsautiClient;
use Esauti\Events\EventType;

$client = new EsautiClient(
    'https://your-mautic-host.com/api',
    ['bearer_token' => 'your-api-token'],
    ['source' => 'my-app']
);

$client->events->send(EventType::CUSTOMER_CREATED, [
    'occurred_at' => date('c'),
    'source'      => 'my-shop',
    'customer'    => [
        'id'    => 'cus_001',
        'email' => '[email protected]',
    ],
]);

$client = new EsautiClient(
    'https://your-mautic-host.com/api',
    [
        'bearer_token' => 'your-api-token',
        'hmac_secret'  => 'your-hmac-secret',  // enables HMAC on all event requests
    ]
);

new EsautiClient(
    string $baseUrl,
    array $auth = [
        'bearer_token' => '...',   // Bearer token
        'hmac_secret'  => '...',   // HMAC signing secret (optional)
    ],
    array $options = [
        'timeout'          => 30,          // Request timeout (seconds)
        'connect_timeout'  => 10,          // Connection timeout (seconds)
        'max_retries'      => 3,           // Retry attempts (408, 429, 5xx, network)
        'debug'            => false,       // Write debug logs to STDERR
        'redact_pii'       => false,       // Redact email/phone in logs
        'events_endpoint'  => '/v1/inbound/event',
        'source'           => 'sdk',       // X-eSauti-Source header
        'logger'           => $myLogger,   // Custom LoggerInterface
        'transport'        => $myTransport, // Custom HttpTransportInterface
    ]
);

use Esauti\Events\EventType;

EventType::CUSTOMER_CREATED     // 'customer.created'
EventType::ORDER_PAID           // 'order.paid'
EventType::SUBSCRIPTION_CREATED // 'subscription.created'
// ... 225 total

use Esauti\Events\DeadLetterSink;
use Esauti\Events\EventRegistry;
use Esauti\Events\EventsClient;

$sink = new DeadLetterSink(function (array $envelope, \Throwable $reason) {
    // Send to your own queue, log, alert, etc.
    myErrorTracker()->capture($reason, ['envelope' => $envelope]);
});

use Esauti\Http\HttpTransportInterface;
use Esauti\Http\Response;

class MyTransport implements HttpTransportInterface {
    public function request(string $method, string $path, array $headers = [], array $query = [], ?array $body = null): Response {
        // your implementation
    }
}

$client = new EsautiClient('https://…', [], ['transport' => new MyTransport()]);
bash
composer