PHP SDK for our API: installing it with Composer and making the first request

API & DocumentationSDKs, CLI & Libraries·· 6 views· 3 min read

If your application is in PHP, this SDK saves you from building requests by hand. It covers all 256 operations of our API, one method per operation: domains, DNS, SMS, E-mail Center, AI, billing, support, servers and the rest. It is generated from the OpenAPI specification, so it keeps up with the API.

What it does

It gives you a client, InterwebMz\Client, with one area per part of the API: domains, dns, sms, emailCenter, ai and the others. The API address is already in the SDK.

It also handles errors, retries and the Idempotency-Key, and checks webhook signatures.

What you need

PHP 7.4 or newer with the curl and json extensions. You install it with Composer; without Composer, require the autoload.php of the package.

And an API key, created in the API Center of Meu Interweb.

Installing, step by step

1 In your project folder, run composer require interweb-mz/sdk.
2 Create a sandbox_ key in the API Center. Put it in the INTERWEB_API_KEY environment variable or pass it in the code.
3 Send your first request, a ping to the API, with the code below.

use InterwebMz\Client;

$client = new Client(); // or new Client(['api_key' => 'sandbox_...'])
echo $client->status->pingGet()['data']['status'];

If the request comes back without an error, the key and the SDK are working. Sending an SMS, for example, looks like this:

$client->sms->messagesCreate(['number' => '+258841234567', 'text' => 'Your order is ready.']);

Complete examples are in the examples/ folder of the repository, and every operation is listed in OPERATIONS.md.

The API key and its permissions

If the key lacks the permission for an operation, the API answers 403 insufficient_scope. Give the key only the permissions of the areas you use: see permissions by area.

Other common errors: 401 unauthorized (wrong or expired key), 402 insufficient_credit (not enough balance) and 429 rate_limited.

Testing without spending

Start with a sandbox_ key: it reads your real data, but writes are simulated and never charge. The X-API-Simulated header, in $client->lastResponse, tells you whether a write was simulated.

Good to know

Retries: on 429 and 5xx, the SDK waits and tries again, up to 2 times by default, and follows Retry-After. Where an operation accepts an Idempotency-Key, it creates one itself, so a request is never done twice.

Webhooks: \InterwebMz\Webhook::verify checks the signature in the X-Webhook-Signature header.

Help

If the API returns an error you do not understand, open a support ticket and send us the correlation_id from the exception, never the key. The code is in the PHP SDK repository, under the MIT license.

Ready to call the API from PHP?

Download the latest release

SEE ALSO

Creating an API key

API permissions by area

Receiving a webhook in PHP and checking its signature

The repository on Interweb Git

SDKs and integrations, in the API documentation

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from $5.36/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.