mesilov / bitrix24-php-sdk
A powerful PHP library for the Bitrix24 REST API
Fund package maintenance!
boosty.to/bitrix24-php-sdk
Installs: 161 097
Dependents: 6
Suggesters: 0
Security: 0
Stars: 389
Watchers: 44
Forks: 156
Open Issues: 33
Requires
- php: 8.2.* || 8.3.*
- ext-bcmath: *
- ext-curl: *
- ext-intl: *
- ext-json: *
- fig/http-message-util: 1.1.*
- moneyphp/money: ^3 || ^4
- psr/log: ^2 || ^3
- ramsey/uuid: ^3 ||^4
- symfony/event-dispatcher: ^6 || ^7
- symfony/http-client: ^6 || ^7
- symfony/http-client-contracts: ^2 || ^3
- symfony/http-foundation: ^6 || ^7
- symfony/uid: ^6 || ^7
Requires (Dev)
- fakerphp/faker: 1.23.*
- monolog/monolog: 3.5.*
- phpstan/phpstan: 1.10.*
- phpunit/phpunit: 11.0.*
- roave/security-advisories: dev-master
- symfony/console: 7.0.*
- symfony/debug-bundle: 7.0.*
- symfony/dotenv: 7.0.*
- symfony/stopwatch: 7.0.*
- dev-master
- 2.x-dev
- 2.0-beta.2
- 2.0-beta.1
- 2.0-alpha.7
- 2.0-alpha.6
- 2.0-alpha.5
- 2.0-alpha.4
- 2.0-alpha.3
- 1.x-dev
- 1.3
- 1.2.2
- 1.2.0
- 1.1.0
- 1.0.0
- 0.7.0
- 0.6.1
- 0.6.0
- 0.4.0
- 0.2.0
- dev-376-add-bizproc-scope-support-in-services
- dev-371-publish-b24-php-sdk-beta-2
- dev-373-bump-dependencies-beta2
- dev-238-update-readmemd-and-examples
- dev-dev
- dev-306-beta-1
- dev-364-add-catalog-scope-support
- dev-303-fix-inconsistency
- dev-302-add-scope-imopenlines
- dev-304-add-telephony-events
- dev-289-add-operating-field-support
- dev-291-add-telephony
- dev-300-add-read-models-for-activity
- dev-274-add-placements
- dev-285-add-userconsent
- dev-283-add-activity
- dev-282-add-lead-support
- dev-280-update-scope
- dev-268-batch-update-entity-items
- dev-225-composite-batch
- dev-issue#217
This package is auto-updated.
Last update: 2024-04-21 14:27:39 UTC
README
A powerful PHP library for the Bitrix24 REST API
Build status
CI\CD status on master |
---|
Integration tests run in GitHub actions with real Bitrix24 portal
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 – constant low memory and
low CPI usage
- batch read data from bitrix24
- batch write data to bitrix24
- write and read in one batch package
- composite batch queries to many entities (work in progress)
- read without count flag
Low-level tools to devs:
- Rate-limit strategy
- Retry strategy for safe methods
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
- 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
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
Sponsors
Help bitrix24-php-sdk by boosty.to/bitrix24-php-sdk
Requirements
- php: >=8.2
- ext-json: *
- ext-curl: *
Installation
Add "mesilov/bitrix24-php-sdk": "2.x"
to composer.json
of your application. Or clone repo to your project.
Examples
Work with webhook
declare(strict_types=1); use Bitrix24\SDK\Services\ServiceBuilderFactory; use Monolog\Logger; use Symfony\Component\EventDispatcher\EventDispatcher; require_once 'vendor/autoload.php'; $webhookUrl = 'INSERT_HERE_YOUR_WEBHOOK_URL'; $log = new Logger('bitrix24-php-sdk'); $b24ServiceFactory = new ServiceBuilderFactory(new EventDispatcher(), $log); // init bitrix24-php-sdk service $b24Service = $b24ServiceFactory->initFromWebhook($webhookUrl); // work with interested scope var_dump($b24Service->getMainScope()->main()->getCurrentUserProfile()->getUserProfile()); var_dump($b24Service->getCRMScope()->lead()->list([],[],['ID','TITLE'])->getLeads()[0]->TITLE);
Tests
Tests locate in folder tests
and we have two test types.
In folder tests create file .env.local
and fill environment variables from .env
.
Unit tests
Fast, in-memory tests without a network I\O For run unit tests you must call in command line
composer phpunit-run-unit-test
Integration tests
Slow tests with full lifecycle with your test Bitrix24 portal via webhook.
❗️Do not run integration tests with production portals
For run integration test you must:
- Create new Bitrix24 portal for development tests
- Go to left menu, click «Sitemap»
- Find menu item «Developer resources»
- Click on menu item «Other»
- Click on menu item «Inbound webhook»
- Assign all permisions with webhook and click «save» button
- Create file
/tests/.env.local
with same settings, see comments in/tests/.env
file.
APP_ENV=dev BITRIX24_WEBHOOK=https:// your portal webhook url INTEGRATION_TEST_LOG_LEVEL=500
- call in command line
composer composer phpunit-run-integration-tests
PHP Static Analysis Tool – phpstan
Call in command line
composer phpstan-analyse
Submitting bugs and feature requests
Bugs and feature request are tracked on GitHub
License
bitrix24-php-sdk is licensed under the MIT License - see the MIT-LICENSE.txt
file for details
Authors
Maksim Mesilov - mesilov.maxim@gmail.com
See also the list of contributors which participated in this project.
Need custom Bitrix24 application?
mesilov.maxim@gmail.com for private consultations or dedicated support
Documentation
Bitrix24 API documentation - Russian