bitrix24/b24phpsdk
Bitrix24 PHP SDK for working with the Bitrix24 REST API from Laravel or plain PHP. Provides typed clients, authentication helpers, API method wrappers, pagination, and webhook/OAuth support to simplify integrating CRM, tasks, chats, and other Bitrix24 modules.
An official PHP library for the Bitrix24 REST API
This library ships two major versions that coexist on separate branches:
v1 (main branch) |
v3 (v3 branch) |
|
|---|---|---|
| PHP | 8.2, 8.3, 8.4 | 8.4, 8.5 |
| API endpoints | {portal}/rest/{user_id}/{token}/{method} |
{portal}/rest/api/{user_id}/{token}/{method} |
| New REST methods | — | ✅ |
| Breaking changes | No | ✅ |
| Semver | 1.* |
3.* |
| Status | Stable / production-ready | Active development |
Which version should I use?
| CI\CD check | main |
v3 |
|---|---|---|
| allowed licenses | ||
| php-cs-fixer | ||
| phpstan | ||
| rector | ||
| deptrac | — | |
| unit tests |
Integration tests run in GitHub actions with real Bitrix24 portal
Install the stable v1 version (PHP 8.2+):
composer require bitrix24/b24phpsdk:"^1.0"
Install the new v3 version (PHP 8.4+, breaking changes):
composer require bitrix24/b24phpsdk:"^3.2"
If you work on Windows:
git config --global core.protectNTFS false for checkout folders starting with a dot.| Branch | Purpose |
|---|---|
main |
Stable v1.x production releases |
dev |
v1.x integration and pre-release testing |
v3 |
Stable v3.x production releases |
v3-dev |
Active v3 development with breaking changes |
Each major version has its own dev branch. Cross-version changes are applied via cherry-pick — branches are never merged across major versions.
Support both auth modes:
Domain core events:
API - level features
Performance improvements 🚀
- http2 protocol via json data structures
- symfony http client
- \Bitrix24\SDK\Core\ApiClient - work with b24 rest-api endpoints
input: arrays \ strings
output: Symfony\Contracts\HttpClient\ResponseInterface, operate with strings
process: network operations
- \Bitrix24\SDK\Services\* - work with b24 rest-api entities
input: arrays \ strings
output: b24 response dto
process: b24 entities, operate with immutable objects
/examples/webhook foldercomposer install
$webhookUrldeclare(strict_types=1);
use Bitrix24\SDK\Services\ServiceBuilderFactory;
require_once 'vendor/autoload.php';
// init bitrix24-php-sdk service from webhook
$b24Service = ServiceBuilderFactory::createServiceBuilderFromWebhook('INSERT_HERE_YOUR_WEBHOOK_URL');
// call some method
var_dump($b24Service->getMainScope()->main()->getApplicationInfo()->applicationInfo());
// call core for method in not implemented service
var_dump($b24Service->core->call('user.current'));
php -f example.php
/examples/local-app foldercomposer install
sudo php -S 127.0.0.1:80
https://****.ngrok-free.appngrok http 127.0.0.1
x-powered-by header with 200 status-code.curl https://****.ngrok-free.app -I
HTTP/2 200
content-type: text/html; charset=UTF-8
date: Mon, 26 Aug 2024 19:09:24 GMT
host: ****.ngrok-free.app
x-powered-by: PHP/8.3.8
type: serverhandler path: https://****.ngrok-free.app/index.phpInitial installation path: https://****.ngrok-free.app/install.phpMenu item text: Test local appscope: crmindex.php file:
Application ID (client_id) — BITRIX24_PHP_SDK_APPLICATION_CLIENT_IDApplication key (client_secret) — BITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRETAssing permitions (scope) — BITRIX24_PHP_SDK_APPLICATION_SCOPEdeclare(strict_types=1);
use Bitrix24\SDK\Core\Credentials\ApplicationProfile;
use Bitrix24\SDK\Services\ServiceBuilderFactory;
use Symfony\Component\HttpFoundation\Request;
require_once 'vendor/autoload.php';
?>
<pre>
Application is worked, auth tokens from bitrix24:
<?= print_r($_REQUEST, true) ?>
</pre>
<?php
$appProfile = ApplicationProfile::initFromArray([
'BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID' => 'INSERT_HERE_YOUR_DATA',
'BITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRET' => 'INSERT_HERE_YOUR_DATA',
'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => 'INSERT_HERE_YOUR_DATA'
]);
$b24Service = ServiceBuilderFactory::createServiceBuilderFromPlacementRequest(Request::createFromGlobals(), $appProfile);
var_dump($b24Service->getMainScope()->main()->getCurrentUserProfile()->getUserProfile());
if you want to create application you can use production-ready contracts in namespace
Bitrix24\SDK\Application\Contracts:
Bitrix24Accounts — Store auth tokens and
provides methods for work with Bitrix24
account.ApplicationInstallations — Store information
about application installation,
linked with Bitrix24 Account with auth
tokens. Optional can store links to:
ContactPersons – Store information about person
who installed application.Bitrix24Partners – Store information
about Bitrix24 Partner who supports client
portal and install or configure application.Steps:
tests/Unit/Application/Contracts/* – examples.Tests locate in folder tests and we have two test types.
In folder tests create file .env.local and fill environment variables from .env.
Call in command line
make lint-phpstan
Call in command line for validate
make lint-rector
Call in command line for fix codebase
make lint-rector-fix
Fast, in-memory tests without a network I\O For run unit tests you must call in command line
make test-unit
Slow tests with full lifecycle with your test Bitrix24 account via webhook.
❗️Do not run integration tests with production Bitrix24 accounts
For running integration test you must:
/tests/.env.local with same settings, see comments in /tests/.env file.BITRIX24_WEBHOOK=https://your-portal.bitrix24.com/rest/1/your-webhook-token/
INTEGRATION_TEST_LOG_LEVEL=100
make test-integration-core
make test-integration-scope-telephony
make test-integration-scope-workflows
make test-integration-scope-user
Bugs and feature request are tracked on GitHub
B24PhpSdk is licensed under the MIT License - see the MIT-LICENSE.txt file for details
How can I help you explore Laravel packages today?