- How do I install **bitrix24/b24phpsdk** in a Laravel project?
- Run `composer require bitrix24/b24phpsdk` in your Laravel project. The SDK registers its service provider automatically, so no manual bootstrapping is needed. Configure your Bitrix24 credentials in `.env` or a config file, and inject the `B24Client` into your controllers or services via Laravel’s dependency injection.
- Which Laravel versions does this SDK support?
- The SDK is designed for Laravel 8.x and 9.x, leveraging features like dependency injection and facades. For Laravel 7.x or older, check the package’s compatibility notes or fork the SDK to adapt to older Laravel versions. Always verify the `composer.json` requirements for the latest version.
- How do I handle OAuth authentication with Bitrix24 in Laravel?
- The SDK simplifies OAuth by providing methods to generate and refresh tokens. Store tokens in Laravel’s cache (e.g., `cache()->remember()`) or database for persistence. Use the `B24Client` facade or service to authenticate requests, and the SDK will handle token refreshes automatically if configured.
- Can I map Bitrix24 CRM entities (like Deals or Contacts) to Laravel Eloquent models?
- Yes, the SDK returns raw API responses, which you can manually map to Eloquent models or custom DTOs. For example, fetch a Bitrix24 Deal and hydrate it into a Laravel model using `create()` or `update()`. Consider using Laravel’s model observers or events to sync changes between Bitrix24 and your database.
- Does the SDK support pagination for Bitrix24 API responses?
- Yes, the SDK includes built-in pagination helpers for Bitrix24 API endpoints. Use methods like `leads()->paginate()` to fetch results in chunks, and the SDK will handle the underlying HTTP requests and response parsing. You can customize pagination limits or offsets as needed.
- How do I handle errors or rate limits from the Bitrix24 API in Laravel?
- The SDK throws `B24ApiException` for API errors, which you can catch in Laravel’s exception handler or middleware. For rate limiting, use Laravel middleware to enforce delays or queue retries. Monitor Bitrix24’s API status and log errors to track issues proactively.
- Can I extend the SDK to support custom Bitrix24 API endpoints?
- Absolutely. The SDK is designed to be extensible. Create a custom service provider or trait to add new endpoints, and bind them to Laravel’s service container. Follow the existing patterns in the SDK’s source code to maintain consistency.
- How do I test my Laravel app’s Bitrix24 integration without hitting the real API?
- Use the `B24ClientInterface` to mock the SDK in your tests. Laravel’s mocking tools (e.g., `Mockery`) can simulate API responses, allowing you to test your business logic without external dependencies. Focus on testing error cases, token handling, and data transformations.
- Is the SDK suitable for production use, or should I use raw Guzzle requests?
- The SDK is production-ready for most use cases, offering abstractions that reduce boilerplate and improve maintainability. However, for high-frequency or performance-critical operations, consider using raw Guzzle requests under the hood or extending the SDK to bypass its abstractions where needed.
- What alternatives exist for integrating Bitrix24 with Laravel if this SDK doesn’t fit?
- Alternatives include using Guzzle directly to call the Bitrix24 REST API or exploring community-built packages like `spatie/laravel-bitrix24`. Evaluate your needs: if you require deep CRM integration, this SDK’s abstractions may save time, while Guzzle offers flexibility for custom workflows.