API quick start

This tutorial will show you how to connect to our API and make function calls. We will write a very simple PHP application which displays information about current balance on your account.

Including the library

In this tutorial we will use composer to install the PHP library:

composer require aftermarketpl/api

If you are not using composer, you can also download and install the library manually - see the document Accessing the API.

Creating the API key

To connect to the API, you need an API key. Click here to create your API key. When asked for key permissions, be sure to include the /account/balance and /account/currency functions. Note down the public and secret key, because you will need it to use the key.

Creating the client class

If yoy already have your API key, it's time to write some PHP code. We will create an API client object, which we will use to issue the calls:

$client = new Aftermarketpl\Api\Client(array(
    "key" => "... your public key ...",
    "secret" => "... your secret key ...",

Making the API calls

In order to retrieve the account balance, we will use the /account/balance function. However, the balance value in itself is meaningless because it needs to be supplemented with the account currency code. So we will also call another function /account/currency to retrieve it, and display the complete information to the user.

Let's write the code to call the two functions:

$balance = $client->send("/account/balance");
$currency = $client->send("/account/currency");
echo "Account balance is: $balance $currency\n";

To make the application complete, you should also include some error handling:

try {
    $balance = $client->send("/account/balance");
    $currency = $client->send("/account/currency");
    echo "Account balance is: $balance $currency\n";
} catch(Aftermarketpl\Api\Exception\Exception $e) {
    echo "Exception: " . $e->getMessage();

That's it! You have just created your first API application. You can now continue to the Detailed documentation or read the API function reference.