PHP code example of braze / sdk

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

    

braze / sdk example snippets




use Braze\Braze;

$braze = new Braze('YOUR_API_URL', 'YOUR_API_KEY');

$client = $braze->client;

use Braze\Client;

$httpClient = \Http\Discovery\Psr18ClientDiscovery::find();
$uri = \Http\Discovery\Psr17FactoryDiscovery::findUriFactory()->createUri('YOUR_API_URL');
$bearer = new \Http\Message\Authentication\Bearer('YOUR_API_KEY');
$plugins = [
    new \Http\Client\Common\Plugin\AddHostPlugin($uri),
    new \Http\Client\Common\Plugin\AuthenticationPlugin($bearer),
];
$httpClient = new \Http\Client\Common\PluginClient($httpClient, $plugins);

$client = Client::create($httpClient);

use Braze\Braze;
use Braze\Model\MessagesSendPostBody;

$braze = new Braze('YOUR_API_URL', 'YOUR_API_KEY');

$braze->client->postMessagesSend(new MessagesSendPostBody([
    'external_user_ids' => ['your_external_user_id'],
    'messages' => [
        'email' => [
            'app_id' => 'your_app_id',
            'from' => 'Company <[email protected]>',
            'email_template_id' => 'your_email_template_id',
        ],
    ],
]));

use Braze\Braze;

$braze = new Braze('YOUR_API_URL', 'YOUR_API_KEY');

try {
    $braze->client->getCatalog();
} catch (Throwable $exception) {
    echo $exception->getMessage();
    echo $exception->getCode();
}