PHP code example of webmens-ru / b24-partners-api-php-sdk

1. Go to this page and download the library: Download webmens-ru/b24-partners-api-php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webmens-ru / b24-partners-api-php-sdk example snippets


use Webmens\B24PartnersApi\PartnerApi;

$api = new PartnerApi(
    accessToken: 'your-access-token',
    refreshToken: 'your-refresh-token',
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret',
);

// Get profile
$profile = $api->profile()->get();
echo $profile->name;

// List cloud clients
$clients = $api->clients()->list(type: 'cloud', limit: 50);
foreach ($clients->items as $client) {
    echo $client->portalUrl;
}

// Create order
use Webmens\B24PartnersApi\Requests\RequestItem;

$request = $api->requests()->create(
    email: '[email protected]',
    portalUrl: 'demo.bitrix24.ru',
    items: [new RequestItem(productId: 16204918, quantity: 1)],
);
echo $request->shortUrl; // Payment link

// Netflow
$attention = $api->netflow()->attentionList(withForecast: true);

use Webmens\B24PartnersApi\Exceptions\ValidationException;
use Webmens\B24PartnersApi\Exceptions\UnauthorizedException;

try {
    $request = $api->requests()->create(...);
} catch (ValidationException $e) {
    foreach ($e->errors as $error) {
        echo "{$error['field']}: {$error['reason']}";
    }
} catch (UnauthorizedException $e) {
    // Refresh failed — need to reissue token
}