PHPackages                             bitrix24/b24phpsdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. bitrix24/b24phpsdk

ActiveLibrary[HTTP &amp; Networking](/categories/http)

bitrix24/b24phpsdk
==================

An official PHP library for the Bitrix24 REST API

3.0.0(2mo ago)9230.2k↑22.1%52[81 issues](https://github.com/bitrix24/b24phpsdk/issues)[4 PRs](https://github.com/bitrix24/b24phpsdk/pulls)3MITPHPPHP 8.4.\* || 8.5.\*CI failing

Since Sep 4Pushed 1mo ago8 watchersCompare

[ Source](https://github.com/bitrix24/b24phpsdk)[ Packagist](https://packagist.org/packages/bitrix24/b24phpsdk)[ Docs](https://github.com/bitrix24/b24phpsdk)[ RSS](/packages/bitrix24-b24phpsdk/feed)WikiDiscussions v3 Synced 1mo ago

READMEChangelog (10)Dependencies (70)Versions (36)Used By (3)

Bitrix24 REST API PHP SDK
=========================

[](#bitrix24-rest-api-php-sdk)

[![Total Downloads](https://camo.githubusercontent.com/01436fe3dac6b25269ec400dca6dbcd97118131757941b0a661d8fc97d71a1e8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62697472697832342f62323470687073646b2e737667)](https://packagist.org/packages/bitrix24/b24phpsdk)[![Latest Stable Version](https://camo.githubusercontent.com/afc5956c8c307bfa56ec42be3033a7a5fed0a78f70cb55cd96cec0f26a9ec255/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62697472697832342f62323470687073646b2e737667)](https://packagist.org/packages/bitrix24/b24phpsdk)

An official PHP library for the Bitrix24 REST API

SDK Versions
------------

[](#sdk-versions)

This library ships two major versions that coexist on separate branches:

v1 (`main` branch)v3 (`v3` branch)**PHP**8.2, 8.3, 8.48.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-readyActive development**Which version should I use?**

- **v1** — choose this for PHP 8.2–8.4 projects, production deployments, or when you don't need the newest Bitrix24 API methods.
- **v3** — choose this for PHP 8.4+ projects that need access to new REST API methods and are comfortable adopting breaking changes.

Build status
------------

[](#build-status)

CI\\CD check[`main`](https://github.com/bitrix24/b24phpsdk/actions?query=branch%3Amain)[`v3`](https://github.com/bitrix24/b24phpsdk/actions?query=branch%3Av3)allowed licenses[![](https://github.com/bitrix24/b24phpsdk/actions/workflows/license-check.yml/badge.svg?branch=main)](https://github.com/bitrix24/b24phpsdk/actions/workflows/license-check.yml)[![](https://github.com/bitrix24/b24phpsdk/actions/workflows/license-check.yml/badge.svg?branch=v3)](https://github.com/bitrix24/b24phpsdk/actions/workflows/license-check.yml)php-cs-fixer[![](https://github.com/bitrix24/b24phpsdk/actions/workflows/php-cs-fixer.yml/badge.svg?branch=main)](https://github.com/bitrix24/b24phpsdk/actions/workflows/php-cs-fixer.yml)[![](https://github.com/bitrix24/b24phpsdk/actions/workflows/php-cs-fixer.yml/badge.svg?branch=v3)](https://github.com/bitrix24/b24phpsdk/actions/workflows/php-cs-fixer.yml)phpstan[![](https://github.com/bitrix24/b24phpsdk/actions/workflows/phpstan.yml/badge.svg?branch=main)](https://github.com/bitrix24/b24phpsdk/actions/workflows/phpstan.yml)[![](https://github.com/bitrix24/b24phpsdk/actions/workflows/phpstan.yml/badge.svg?branch=v3)](https://github.com/bitrix24/b24phpsdk/actions/workflows/phpstan.yml)rector[![](https://github.com/bitrix24/b24phpsdk/actions/workflows/rector.yml/badge.svg?branch=main)](https://github.com/bitrix24/b24phpsdk/actions/workflows/rector.yml)[![](https://github.com/bitrix24/b24phpsdk/actions/workflows/rector.yml/badge.svg?branch=v3)](https://github.com/bitrix24/b24phpsdk/actions/workflows/rector.yml)deptrac—[![](https://github.com/bitrix24/b24phpsdk/actions/workflows/deptrac.yml/badge.svg?branch=v3)](https://github.com/bitrix24/b24phpsdk/actions/workflows/deptrac.yml)unit tests[![](https://github.com/bitrix24/b24phpsdk/actions/workflows/phpunit.yml/badge.svg?branch=main)](https://github.com/bitrix24/b24phpsdk/actions/workflows/phpunit.yml)[![](https://github.com/bitrix24/b24phpsdk/actions/workflows/phpunit.yml/badge.svg?branch=v3)](https://github.com/bitrix24/b24phpsdk/actions/workflows/phpunit.yml)Integration tests run in GitHub actions with real Bitrix24 portal

Installation
------------

[](#installation)

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.0"
```

If you work on Windows:

- please use [WSL - Windows Subsystem for Linux](https://learn.microsoft.com/en-us/windows/wsl/)
- if your filesystem is NTFS, you can disable the flag `git config --global core.protectNTFS false` for checkout folders starting with a dot.

Branch status
-------------

[](#branch-status)

BranchPurpose`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 changesEach major version has its own `dev` branch. Cross-version changes are applied via cherry-pick — branches are never merged across major versions.

B24PhpSdk ✨FEATURES✨
--------------------

[](#b24phpsdk-features)

Support both auth modes:

- work with auth tokens for mass-market Bitrix24 applications
- work with incoming webhooks for simple integration projects for a single Bitrix24 account

Domain core events:

- Access Token expired
- Url of a Bitrix24 account domain changed

API - level features

- Auto renew access tokens
- List queries with «start=-1» support
- offline queues

Performance improvements 🚀

- Batch queries implemented with [PHP Generators](https://www.php.net/manual/en/language.generators.overview.php) – constant low memory and low CPI usage:
- batch read data from bitrix24
- batch write data to bitrix24
- read without count flag

Development principles
----------------------

[](#development-principles)

- Good developer experience
    - auto-completion of methods at the IDE
    - typed method call signatures
    - typed results of method calls
    - helpers for typical operations
- Good documentation
    - documentation on the operation of a specific method containing a link to the official documentation
    - documentation for working with the SDK
- Performance first:
    - minimal impact on client code
    - ability to work with large amounts of data with constant memory consumption
    - efficient operation of the API using batch requests
- Modern technology stack
    - based on [Symfony HttpClient](https://symfony.com/doc/current/http_client.html)
    - actual PHP versions language features
- Reliable:
    - test coverage: unit, integration, contract
    - typical examples typical for different modes of operation and they are optimized for memory \\ performance

Architecture
------------

[](#architecture)

### Abstraction layers

[](#abstraction-layers)

```
- 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

```

Documentation
-------------

[](#documentation)

- [Bitrix24 API documentation - English](https://apidocs.bitrix24.com/)

Requirements
------------

[](#requirements)

- php: &gt;=8.2
- ext-json: \*
- ext-curl: \*

Examples
--------

[](#examples)

### Work with webhook

[](#work-with-webhook)

1. Go to `/examples/webhook` folder
2. Open console and install dependencies

```
composer install
```

3. Open Bitrix24 account: Developer resources → Other → Inbound webhook
4. Open example file and insert webhook url into `$webhookUrl`

```
declare(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'));
```

5. Call php file in shell

```
php -f example.php
```

### Work with local application

[](#work-with-local-application)

1. Go to `/examples/local-app` folder
2. Open console and install dependencies

```
composer install
```

3. Start local development server

```
sudo php -S 127.0.0.1:80
```

4. Expose local server to public via [ngrok](https://ngrok.com/) and remember temporally public url – `https://****.ngrok-free.app`

```
ngrok http 127.0.0.1
```

5. Check public url from ngrok and see `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
```

6. Open Bitrix24 account: Developer resources → Other → Local application and create new local application:
    - `type`: server
    - `handler path`: `https://****.ngrok-free.app/index.php`
    - `Initial installation path`: `https://****.ngrok-free.app/install.php`
    - `Menu item text`: `Test local app`
    - `scope`: `crm`
7. Save application parameters in `index.php` file:
    - `Application ID (client_id)` — `BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID`
    - `Application key (client_secret)` — `BITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRET`
    - `Assing permitions (scope)` — `BITRIX24_PHP_SDK_APPLICATION_SCOPE`

 see index.php file```
declare(strict_types=1);

use Bitrix24\SDK\Core\Credentials\ApplicationProfile;
use Bitrix24\SDK\Services\ServiceBuilderFactory;
use Symfony\Component\HttpFoundation\Request;

require_once 'vendor/autoload.php';
?>

    Application is worked, auth tokens from bitrix24:
