This is the documentation for the PHP client for Salesfly® API. You can find the source code for the client on GitHub. We have API clients in several other programming languages hosted on GitHub.


The PHP client for Salesfly API requires PHP version 7.1 or later. If you’re using a Mac or Linux machine, you probably already have PHP installed. You can check this by opening up a terminal and running the following command:

php --version

If it is not installed, follow the PHP installation instructions.

If you're using a Windows machine, please follow the official PHP tutorial to install PHP.


While many versions of PHP will work for this quickstart, please pay attention to supported PHP releases. Always update unsupported versions when doing web development, as older versions will not receive security updates.


The easiest way to install salesfly-php is using Composer. Composer is the de facto standard package manager for PHP web development. If you haven't yet installed it, here are the installation instructions for your platform:

composer require salesfly/client

Alternatively, you can create a file named composer.json. In that file, add:

  "require": {
    "salesfly/client": "^1.0"

Then run

composer install

And composer will install the latest 1.x version of the PHP client for Salesfly API.


Now that we have PHP and salesfly-php installed, we can start using the API. In the example below we will look up the geolocation of the IP address

use Salesfly\Client;


$client = new Client($apiKey);
$location = $client->geoip->get("");

echo "Country code: " . $location["country_code"];

Error handling

The API client will throw an APIException upon error, and you handle the errors in the normal way with a try-catch statement. APIException has three subclasses: APIConnectionException, APITimeoutException and ResponseException.

If you enter an invalid IP address, you will get an exception:

use Salesfly\Client;
use Salesfly\Exceptions\ResponseException;


$client = new Client($apiKey);

try {
    $location = $this->client->geolocation->get("x");
} catch (ResponseException $e) {
    echo "API request failed:";
    echo "* Status: " . $e->getStatus();
    echo "* Code: " . $e->getErrorCode();
    echo "* Message: " . $e->getMessage();

The example above will print the following:

API request failed:
* Status: 400
* Code: err-invalid-ip
* Message: Invalid IP address

You should use the getErrorCode() method to determine the reason for the error. Please observe that this is not the same method as Exception::getCode().

You will find all the error codes in the REST API documentation.