webparking / logic4-client
Unofficial PHP client for the Logic4 API, generated from Logic4's OpenAPI documentation
Requires
- php: ^8.3
- guzzlehttp/guzzle: ^7.8
- nesbot/carbon: ^2.72|^3.8
- psr/simple-cache: ^3.0
Requires (Dev)
- cebe/php-openapi: ^1.7
- friendsofphp/php-cs-fixer: ^3.35
- mockery/mockery: ^1.6
- nette/php-generator: ^4.1
- orchestra/testbench: ^10.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.10
- phpstan/phpstan-mockery: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- phpunit/phpunit: ^11.5
- rector/rector: ^1.1.1
- rregeer/phpunit-coverage-check: ^0.3.1
- symfony/var-dumper: ^7.2
- webmozart/assert: ^1.12
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- v4.1.0-beta.1
- v4.0.1
- v4.0.0
- v4.0.0-alpha.1
- v3.1.9
- v3.1.8
- v3.1.7
- v3.1.6
- v3.1.5
- v3.1.4
- v3.1.3
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.9
- v3.0.8
- v3.0.7
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.x-dev
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.0
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.2
- v2.0.1
- v2.0.0
- v1.0.0
- dev-feature/php-8.5-compatibility
- dev-feature/beta-tracking
- dev-bugfix/LKCAPIBRIDGENL-1V-product-media-enum-dto
- dev-feature/add-v3-api-namespace-only
- dev-feature/generate-v3-api-namespace
- dev-feature/handle-required-better
- dev-feature/support-version-3
- dev-feature/to-v2-urls
- dev-more-accurate-nullables
- dev-add-webmozart-assert
- dev-array-type-endpoints
- dev-nullabe-request-body-properties
- dev-improvement/dto-per-api-version
- dev-generator-v2
- dev-feature/improve-pagination-support
- dev-bugfix/missing-request-parameters
This package is auto-updated.
Last update: 2026-11-02 15:38:14 UTC
README
Logic4 client
Unofficial PHP client for the Logic4 API. The request classes, response objects and endpoint reference are generated from Logic4's own OpenAPI documentation and checked for changes every day. The client covers Logic4 API v1.0 through v3.1, takes care of the OAuth access token and returns typed objects instead of raw arrays.
This package is not created or maintained by Logic4. For questions about Logic4 or its API, contact Logic4 support.
Requirements
- PHP 8.3 or newer
- A PSR-16 cache implementation to store the access token
- Laravel is optional; the client works in any PHP application
Installation
composer require webparking/logic4-client
Beta builds generated from Logic4's QA environment are published as prereleases:
composer require webparking/logic4-client:4.1.0-beta.1
Quick start
Any PSR-16 cache works for the access token. This example uses symfony/cache:
use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Psr16Cache; use Webparking\Logic4Client\AccessTokenManager; use Webparking\Logic4Client\ClientFactory; use Webparking\Logic4Client\Requests\V11\ProductRequest; $tokenManager = new AccessTokenManager(new Psr16Cache(new FilesystemAdapter())); $tokenManager->configure([ 'public_key' => $_ENV['LOGIC4_PUBLIC_KEY'], 'company_key' => $_ENV['LOGIC4_COMPANY_KEY'], 'username' => $_ENV['LOGIC4_USERNAME'], 'secret_key' => $_ENV['LOGIC4_SECRET_KEY'], 'password' => $_ENV['LOGIC4_PASSWORD'], 'administration_id' => $_ENV['LOGIC4_ADMINISTRATION_ID'], ]); $products = new ProductRequest(new ClientFactory($tokenManager)); foreach ($products->getProducts(['DebtorId' => 1]) as $product) { echo $product->productId, \PHP_EOL; }
Every request class lives in a namespace named after the Logic4 API version it talks to: Requests\V11\ProductRequest calls /v1.1/Products/... and Requests\V30\ProductRequest calls /v3/Products/.... Pick the highest version that has the endpoint you need. See Choosing an API version.
Laravel
Laravel binds Psr\SimpleCache\CacheInterface to your default cache store, so the container can build AccessTokenManager on its own. Supply the credentials once, in the register() method of a service provider:
use Illuminate\Support\ServiceProvider; use Webparking\Logic4Client\AccessTokenManager; final class Logic4ServiceProvider extends ServiceProvider { public function register(): void { $this->app->afterResolving(AccessTokenManager::class, static fn (AccessTokenManager $tokenManager) => $tokenManager->configure([ 'public_key' => config('services.logic4.public_key'), 'company_key' => config('services.logic4.company_key'), 'username' => config('services.logic4.username'), 'secret_key' => config('services.logic4.secret_key'), 'password' => config('services.logic4.password'), 'administration_id' => config('services.logic4.administration_id'), ])); } }
Request classes can then be injected anywhere:
use Webparking\Logic4Client\Requests\V11\ProductRequest; final class ProductController { public function __invoke(ProductRequest $products): array { return iterator_to_array($products->getProducts(['DebtorId' => 1])); } }
The full setup, including config/services.php, is in Getting started.
Responses
Endpoint methods return one of three shapes. The method signature and its @return docblock tell you which.
| Shape | Where | Example | How to read it |
|---|---|---|---|
\Generator<DTO> |
Paginated lists in V10 to V20 | V11\ProductRequest::getProducts() |
foreach over it. Pages of 1000 records load as you go. iterator_to_array() loads everything. |
*Logic4ResponseList |
Other lists in V10 to V20 | V10\ProductGroupsRequest::getProductGroups() |
->records, ->recordsCounter, ->validationMessages |
array, string, int, bool, void or a single object |
V30 and V31 | V30\ProductRequest::getProducts() |
Plain PHP values. Objects live in Responses\V30. |
Details and pagination options are in Responses.
Errors
Every HTTP status of 400 or higher becomes a Logic4ApiException, with the Guzzle exception attached as previous:
use Webparking\Logic4Client\Exceptions\Logic4ApiException; try { $groups = $request->getProductGroups(['IsTopLevelGroup' => true]); } catch (Logic4ApiException $exception) { report($exception->getPrevious() ?? $exception); }
Transport failures, token failures and validation messages are covered in Errors.
Testing your integration
Give a request class a mocked Guzzle client with setClient(), or enable ClientFactory::preventStrayRequests() in your test case so every unmocked call throws. Examples for Mockery, Guzzle's MockHandler and Laravel are in Testing.
Documentation
- Getting started: credentials, plain PHP and Laravel setup, request lifecycle
- Choosing an API version: what the
V10toV31namespaces mean and which ones still change - Responses: generators, envelopes, plain values, pagination
- Errors: exceptions, validation messages, retries
- Configuration: every constructor argument, cache behaviour, QA environment
- Testing: mocking patterns for your own test suite
- Endpoint reference: every request class and method per API version
- Changelog and upgrade guide
- Logic4's own API documentation: production and QA
Contributing
Bug reports and pull requests are welcome. CONTRIBUTING.md explains the development environment, the generator and the release process. Security issues go through SECURITY.md.
The client only follows what Logic4 documents. Open an issue when a documented endpoint is missing or generated incorrectly; requests for new Logic4 functionality belong with Logic4 itself.
License
The MIT License (MIT). Please see the license file for more information.
