PHP code example of dmt-software / laposta-api

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

    

dmt-software / laposta-api example snippets

 
// file: config.php

return [
    'apiKey' => 'JdMtbsMq2jqJdQZD9AHC',
    'customFieldsClasses' => [],
    'httpClient' => \GuzzleHttp\Client::class,
    'requestFactory' => \GuzzleHttp\Psr7\HttpFactory::class,
];

use DMT\Laposta\Api\Clients\Subscribers;
use DMT\Laposta\Api\Config;
use DMT\Laposta\Api\Factories\CommandBusFactory;

$commandBus = CommandBusFactory::create(Config::load('config.php'));

$client = new Subscribers($commandBus);

use DMT\CommandBus\Validator\ValidationException;
use DMT\Laposta\Api\Entity\BaseCustomFields;
use DMT\Laposta\Api\Entity\Subscriber;
use DMT\Laposta\Api\Clients\Subscribers;
use Psr\Http\Client\ClientExceptionInterface;

try {
    /** @var BaseCustomFields $customFields The generated entity for your list */
    
    $subscriber = new Subscriber();
    $subscriber->listId = 'BaImMu3JZA';
    $subscriber->email = '[email protected]';
    $subscriber->customFields = $customFields;
    $subscriber->customFields->name = 'John Do';
    
    /** @var Subscribers $client */
    $client->create($subscriber, Subscribers::OPTION_SUPPRESS_EMAIL_NOTIFICATION);
} catch (ValidationException $exception) {
     // input was wrong 
} catch (ClientExceptionInterface $exception) {
    // error response
}