PHP SDK

Call the revenexx API from PHP with a typed client that handles auth, requests, and responses.

revenexx/sdk is the typed client for the revenexx API from PHP servers and apps. Like the Web SDK, you configure the endpoint, your tenant, and a credential once, then call methods on a service. This is a server-side client, so it usually uses a machine-to-machine API key.

Status: first version.

Install

The Composer package is revenexx/sdk. It requires PHP 8.1 or newer with the curl and json extensions.

Composer
composer require revenexx/sdk

Configure the client

Create a Client, set the endpoint and tenant, and add your API key.

PHP
<?php

require __DIR__ . '/vendor/autoload.php';

use RevenexxAPIRevenexx\Client;

$client = (new Client())
    ->setEndpoint('https://api.revenexx.com')
    ->setTenant('<TENANT_SLUG>')
    ->setApiKeyAuth('rvxk_...');

The auth methods mirror the Web SDK and set the same headers:

MethodHeader it setsWhen to use it
setApiKeyAuth($key)X-Revenexx-Api-KeyServer-to-server. Created in the customer console.
setBearerAuth($token)AuthorizationA user token from ID or a personal access token. Pass the value including the Bearer prefix.
setTenant($slug)X-Revenexx-TenantAlways — selects which tenant the request applies to.

The tenant slug rides on every request as the X-Revenexx-Tenant header. There's one gateway, https://api.revenexx.com — no per-region host to configure.

Make a call

Construct a service with the client, then call its methods.

PHP
<?php

use RevenexxAPIRevenexx\Services\Products;

$products = new Products($client);

$result  = $products->productsList();
$product = $products->productsGet(id: '<PRODUCT_ID>');

Handle errors

Failed calls throw a RevenexxAPIRevenexxException carrying the message, an error code, and the raw response.

PHP
<?php

use RevenexxAPIRevenexx\RevenexxAPIRevenexxException;
use RevenexxAPIRevenexx\Services\Products;

$products = new Products($client);

try {
    $product = $products->productsGet(id: '<PRODUCT_ID>');
} catch (RevenexxAPIRevenexxException $error) {
    echo $error->getMessage();
}

What's available

The client exposes a service per API area, matching the Web SDK: Customers, Products, Orders, Carts, Payments, Shipping, Prices, Inventories, Storage, and more. The set of services and methods is generated from your tenant's API. Browse them in your editor, or read the per-tenant API at /v1/openapi.json.

Where to go next

Was this page helpful?