keboola / query-api-php-client
Keboola Query Service API PHP Client
Package info
github.com/keboola/query-service-api-php-client
pkg:composer/keboola/query-api-php-client
Requires
- php: ^8.4
- guzzlehttp/guzzle: ^7.8
- keboola/php-api-client-base: ^1.1.1
- psr/http-message: ^1.0|^2.0
- psr/log: ^1.0|^2.0|^3.0
- webmozart/assert: ^1.11
Requires (Dev)
- keboola/coding-standard: ^16.0
- keboola/storage-api-client: ^18.0
- phpstan/phpstan: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-webmozart-assert: ^2.0
- phpunit/phpunit: ^11.0
- squizlabs/php_codesniffer: ^3
- symfony/dotenv: ^7.0
This package is auto-updated.
Last update: 2026-07-26 12:21:17 UTC
README
PHP client for the Keboola Query Service API, built on keboola/php-api-client-base.
Installation
composer require keboola/query-api-php-client
Usage
<?php use Keboola\QueryApi\Client; $client = new Client( 'https://query.keboola.com', // base URL 'your-storage-api-token', // X-StorageApi-Token ); // Submit a query job $response = $client->submitQueryJob('main', 'workspace-123', [ 'statements' => ['SELECT * FROM table1'], 'transactional' => true, ]); $queryJobId = $response->getQueryJobId(); // Poll until it finishes $status = $client->waitForJobCompletion($queryJobId); // Read results for the first completed statement $statementId = $status->getStatements()[0]->getId(); $results = $client->getJobResults($queryJobId, $statementId); foreach ($results->getData() as $row) { // ... } // Cancel if needed $client->cancelJob($queryJobId, ['reason' => 'User requested cancellation']);
Constructor options
new Client( string $baseUrl, string $storageToken, ?string $runId = null, // sent as X-KBC-RunId on every request ?Psr\Log\LoggerInterface $logger = null, int $backoffMaxTries = 3, // retries on 5xx / transport errors, never 4xx int $connectTimeout = 10, int $requestTimeout = 120, string $userAgent = 'Keboola Query API PHP Client', null|Closure|GuzzleHttp\HandlerStack $requestHandler = null, // inject a mock handler in tests );
Errors
All failures throw Keboola\QueryApi\Exception\ClientException (a subclass of the base client's
exception). It exposes getStatusCode(): ?int and getResponseBody(): ?string; the message is
taken from the API response's exception field when present.
Development
Run inside the library's docker service:
composer install
composer ci # validate + phpcs + phpstan + phpunit
Functional tests (tests/Functional/) require STORAGE_API_TOKEN, HOSTNAME_SUFFIX
(the Query Service URL is https://query.{HOSTNAME_SUFFIX}) and STORAGE_API_URL.
License
MIT — see LICENSE.