Skip to content

Commit

Permalink
docs: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Aug 13, 2023
1 parent a9a617f commit 90a07fc
Showing 1 changed file with 135 additions and 0 deletions.
135 changes: 135 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,136 @@
# braze-php

PHP library for [Braze](https://www.braze.com/). Code is generated using the [OpenAPI spec](https://github.com/braze-community/braze-specification).

## Requirements

### Version

PHP >=7.4

### API URL

Use the [REST endpoint](https://www.braze.com/docs/api/basics#endpoints) provisioned to your account when you log in to the dashboard:

| Instance | REST Endpoint |
| -------- | ----------------------------- |
| US-01 | https://rest.iad-01.braze.com |
| US-02 | https://rest.iad-02.braze.com |
| US-03 | https://rest.iad-03.braze.com |
| US-04 | https://rest.iad-04.braze.com |
| US-05 | https://rest.iad-05.braze.com |
| US-06 | https://rest.iad-06.braze.com |
| US-08 | https://rest.iad-08.braze.com |
| EU-01 | https://rest.fra-01.braze.eu |
| EU-02 | https://rest.fra-02.braze.eu |

### API Key

The [API key](https://www.braze.com/docs/api/basics#creating-and-managing-rest-api-keys) can be created in your Braze dashboard.

## Install

Install with [Composer](http://getcomposer.org/):

```sh
composer require braze/sdk
```

Use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):

```php
require_once 'vendor/autoload.php';
```

## Usage

Instantiate the client:

```php
use Braze\Braze;

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

$client = $braze->client;
```

Or create a custom client:

```php
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:

```php
use Braze\Braze;

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

$braze->client->postMessagesSend((object) [
'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:

```php
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:

```sh
composer build
```

### `composer clean`

Delete the `lib/` directory:

```sh
composer clean
```

### `composer test`

Run the tests:

```sh
composer test
```

## About This Package

This package is automatically generated by [Jane](https://github.com/janephp/janephp).

0 comments on commit 90a07fc

Please sign in to comment.