This repository contains the open source PHP client for MessageBird's REST API. Documentation can be found at: https://developers.messagebird.com/
- Sign up for a free MessageBird account
- Create a new access_key in the developers sections
- MessageBird API client for PHP requires PHP >= 7.0.
- Download composer
- Run
composer require messagebird/php-rest-api
.
When you do not use Composer. You can git checkout or download this repository and include the MessageBird API client manually.
We have put some self-explanatory examples in the examples directory, but here is a quick breakdown on how it works. The examples expect the api key to be available in the env var MESSAGEBIRD_API_KEY. So make sure to set it when running the example.
require 'autoload.php';
$MessageBird = new \MessageBird\Client(getenv('MESSAGEBIRD_API_KEY'));
Run your script with:
MESSAGEBIRD_API_KEY={your API key here} php your-script.php
That's easy enough. Now we can query the server for information. Lets use getting your balance overview as an example:
// Get your balance
$Balance = $MessageBird->balance->read();
To use the whatsapp sandbox you need to add \MessageBird\Client::ENABLE_CONVERSATIONSAPI_WHATSAPP_SANDBOX
to the list of features you want enabled. Don't forget to set the env var MESSAGEBIRD_API_KEY when running the example.
$messageBird = new \MessageBird\Client(getenv('MESSAGEBIRD_API_KEY'), null, [\MessageBird\Client::ENABLE_CONVERSATIONSAPI_WHATSAPP_SANDBOX]);
If you use a custom HttpClient
you will have to manually direct Conversation API request to the WhatsApp sandbox endpoint.
Complete documentation, instructions, and examples are available at: https://developers.messagebird.com/
The MessageBird REST Client for PHP is licensed under The BSD 2-Clause License. Copyright (c) 2014, MessageBird