braze/sdk

Track users, send messages, export data, and more with Braze API.

2.2.2 2024-10-15 00:10 UTC

README

packagist build test

PHP library for Braze. Code is generated using the OpenAPI spec.

Requirements

Version

PHP >=8.0

API URL

Use the REST endpoint provisioned to your account when you log in to the dashboard:

API Key

The API key can be created in your Braze dashboard.

Install

Install with Composer:

composer require braze/sdk

Use Composer's autoload:

require_once 'vendor/autoload.php';

Usage

Instantiate the client:

use Braze\Braze;

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

$client = $braze->client;

Or create a custom 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);

Send a message to your user:

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 <company@example.com>',
            'email_template_id' => 'your_email_template_id',
        ],
    ],
]));

Handle an API error:

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();
}

Scripts

composer build

Generate the code:

composer build

composer clean

Delete the lib/ directory:

composer clean

composer test

Run the tests:

composer test

About This Package

This package is automatically generated by Jane.