PHPackages                             mesilov/bitrix24-php-sdk - 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. mesilov/bitrix24-php-sdk

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

mesilov/bitrix24-php-sdk
========================

A powerful PHP library for the Bitrix24 REST API

2.0(1y ago)416215.8k—9.4%1583MITPHPPHP 8.2.\* || 8.3.\*CI passing

Since Jun 23Pushed 1y ago46 watchersCompare

[ Source](https://github.com/mesilov/bitrix24-php-sdk)[ Packagist](https://packagist.org/packages/mesilov/bitrix24-php-sdk)[ Docs](https://github.com/mesilov/bitrix24-php-sdk)[ Fund](https://boosty.to/bitrix24-php-sdk)[ RSS](/packages/mesilov-bitrix24-php-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (28)Versions (29)Used By (3)

❗️Bitrix24 forked this repository 🥳 and now I contribute [there](https://github.com/bitrix24/b24phpsdk)
=======================================================================================================

[](#️bitrix24-forked-this-repository--and-now-i-contribute-there)

❗️For new and existing projects please use
==================================================================================

[](#️for-new-and-existing-projects-please-use-httpsgithubcombitrix24b24phpsdk)

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

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

[![License](https://camo.githubusercontent.com/2a7fa6b5dc7724d0cfec3be5acaea40124da12360fa322523b50dfd3edb88533/68747470733a2f2f706f7365722e707567782e6f72672f6d6573696c6f762f62697472697832342d7068702d73646b2f6c6963656e73652e737667)](https://packagist.org/packages/mesilov/bitrix24-php-sdk) [![Total Downloads](https://camo.githubusercontent.com/3a6609b78c0fc30082f06931baf4a76a06ed78956cfe5f69b02cb25680bb785a/68747470733a2f2f706f7365722e707567782e6f72672f6d6573696c6f762f62697472697832342d7068702d73646b2f646f776e6c6f6164732e737667)](https://packagist.org/packages/mesilov/bitrix24-php-sdk)[![Latest Stable Version](https://camo.githubusercontent.com/dd98300e67c5ebe98a37ddb7601b988d767522d5a9581cba5e8f4df9feab8531/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6573696c6f762f62697472697832342d7068702d73646b2e737667)](https://packagist.org/packages/mesilov/bitrix24-php-sdk)

A powerful PHP library for the Bitrix24 REST API

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

[](#build-status)

CI\\CD [status](https://github.com/mesilov/bitrix24-php-sdk/actions) on `master`[![phpstan check](https://github.com/mesilov/bitrix24-php-sdk/actions/workflows/phpstan.yml/badge.svg)](https://github.com/mesilov/bitrix24-php-sdk/actions/workflows/phpstan.yml)[![unit-tests status](https://github.com/mesilov/bitrix24-php-sdk/actions/workflows/phpunit.yml/badge.svg)](https://github.com/mesilov/bitrix24-php-sdk/actions/workflows/phpunit.yml)Integration tests run in GitHub actions with real Bitrix24 portal

BITRIX24-PHP-SDK ✨FEATURES✨
---------------------------

[](#bitrix24-php-sdk-features)

Support both auth modes:

- work with auth tokens for Bitrix24 applications in marketplace
- work with incoming webhooks for simple integration projects for current portal

Domain core events:

- Access Token expired
- Bitrix24 portal domain url 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://training.bitrix24.com/rest_help/)
- [Internal documentation](docs/EN/documentation.md) for bitrix24-php-sdk

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

[](#requirements)

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

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

[](#installation)

Add `"mesilov/bitrix24-php-sdk": "2.x"` to `composer.json` of your application. Or clone repo to your project.

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 portal: Developer resources → Other → Inbound webhook
4. Open example file and insert webhook url into `$webhookUrl`

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

use Bitrix24\SDK\Services\ServiceBuilderFactory;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Processor\MemoryUsageProcessor;

require_once 'vendor/autoload.php';

$webhookUrl = 'INSERT_HERE_YOUR_WEBHOOK_URL';

$log = new Logger('bitrix24-php-sdk');
$log->pushHandler(new StreamHandler('bitrix24-php-sdk.log'));
$log->pushProcessor(new MemoryUsageProcessor(true, true));

// create service builder factory
$b24ServiceFactory = new ServiceBuilderFactory(new EventDispatcher(), $log);
// init bitrix24-php-sdk service from webhook
$b24Service = $b24ServiceFactory->initFromWebhook($webhookUrl);

// work with interested scope
var_dump($b24Service->getMainScope()->main()->getCurrentUserProfile()->getUserProfile());
// get deals list and address to first element
var_dump($b24Service->getCRMScope()->lead()->list([], [], ['ID', 'TITLE'])->getLeads()[0]->TITLE);
```

5. Call php file in shell

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

### Work with local application

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

1. Go to `/examples/local-application` 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 portal: 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\AuthToken;
use Bitrix24\SDK\Core\Credentials\ApplicationProfile;
use Bitrix24\SDK\Services\ServiceBuilderFactory;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Monolog\Processor\MemoryUsageProcessor;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;

require_once 'vendor/autoload.php';
?>

    Application is worked, auth tokens from bitrix24:
