The PHP SDK provides a comprehensive library for easily integrating with the Mambo API. This client library simplifies development by handling authentication, request formatting, and response parsing, allowing you to focus on your application logic. The SDK includes examples for most of the APIs as well as a compatibility check to verify if you can use it with your current setup.
To connect to the Mambo API, use one of the service classes provided in the services package. See the code samples below for implementation examples.
Installation
Requirements
Dependencies
Composer
After downloading the Mambo SDK, you can import it into your project by adding the following to your composer.json file and then using Composer's autoload:
{
"repositories": [
{
"type": "path",
"url": "path/to/sdk/"
}
],
"require": {
"mambo/mambo": "*"
}
}
Manual installation
If you are not using Composer, after downloading the Mambo SDK you can initialise it manually:
require_once 'path/to/sdk/MamboInit.php';
Downloads
The Mambo SDK requires the following files to be installed manually:
Version: Latest (8.7.2) 8.6.5 8.5.0 8.4.2 8.3.1 8.2.1 8.1.3 8.0.4 7.7.1 7.6.1 7.5.0 7.4.5 7.3.3 7.2.1 7.1.1 7.0.3 6.3.6 6.2.4 6.1.2 6.0.1
Documentation
Client initialisation
To initialise the SDK, you'll need to set your credentials and, if using an on-premise installation, the API endpoint URL:
// Initialisation with client credentials only
$client = new MamboClient( 'public_key', 'private_key' );
// Initialisation with advanced configuration options
$configuration = new ClientConfiguration();
$configuration->setCredentials('public_key', 'private_key');
$configuration->setServerBaseUrl('https://api.mambo.io');
$configuration->setDebug(false);
$configuration->setLanguage('en');
$configuration->setJsonDecodeAsArray(false);
$configuration->setTimeoutMilliseconds(60000);
$configuration->setConnectTimeoutMilliseconds(20000);
$client = MamboClient::withConfiguration($configuration);
$client->activities()->createAsync( ... );
Query parameters
Use parameter objects to provide query parameters to endpoint methods:
$params = new UserGetPointWalletsParams();
$params->pageSize(10);
$client->users()->getPointWallets( 'acmeinc', 'user_uuid', $params );
Request options
Use the request options object to provide configuration on a per-request basis. This object can be used to provide idempotency keys or request specific timeouts:
$requestOptions = new RequestOptions();
$requestOptions->setIdempotencyKey( '8e455f7a-8cc9-4da9-8454-34bd082d19cb' );
$client->activities()->createAsync( 'acmeinc', $data, $requestOptions );
Getting started
Here's a complete example showing how to initialise the client and make a basic API call:
<?php
require_once 'vendor/autoload.php'; // If using Composer
// require_once 'path/to/sdk/MamboInit.php'; // If using manual installation
// Create client with your API credentials
$client = new MamboClient( 'your_public_key', 'your_private_key' );
// Create activity data
$attrs = new ActivityBehaviourAttrsData();
$attrs->setVerb( 'purchase' );
$data = new ActivityRequestData();
$data->setUUID( 'user_uuid' );
$data->setAttrs( $attrs );
// Call API and handle response
try {
$id = $client->activities()->createAsync( 'acmeinc', $data );
echo "Activity created with ID: " . $id;
} catch (Exception $e) {
echo "Error creating activity: " . $e->getMessage();
}
Troubleshooting
Common issues
Connection timeouts
If you experience connection timeouts, you can increase the timeout settings when initialising the client:
$configuration = new ClientConfiguration();
$configuration->setCredentials('public_key', 'private_key');
$configuration->setTimeoutMilliseconds(60000); // 1 minute
$configuration->setConnectTimeoutMilliseconds(30000); // 30 seconds
$client = MamboClient::withConfiguration($configuration);
Debugging
Enable debug mode to troubleshoot issues:
$configuration = new ClientConfiguration();
$configuration->setCredentials('public_key', 'private_key');
$configuration->setDebug(true);
$client = MamboClient::withConfiguration($configuration);