PHP client for Keboola Query Service API.
composer require keboola/query-api-php-client
<?php
use Keboola\QueryApi\Client;
$client = new Client([
'url' => 'https://query.keboola.com',
'token' => 'your-storage-api-token'
]);
// Submit a query job
$response = $client->submitQueryJob('main', 'workspace-123', [
'statements' => ['SELECT * FROM table1'],
'transactional' => true
]);
$queryJobId = $response['queryJobId'];
// Get job status
$status = $client->getJobStatus($queryJobId);
// Get job results
$results = $client->getJobResults($queryJobId, $statementId);
// Cancel job
$client->cancelJob($queryJobId, ['reason' => 'User requested cancellation']);
// Health check
$health = $client->healthCheck();
The client constructor accepts the following configuration options:
url
(required): Query Service API URL (e.g.,https://query.keboola.com
)token
(required): Storage API tokenbackoffMaxTries
(optional): Number of retry attempts for failed requests (default: 3)userAgent
(optional): Additional user agent string to appendhandler
(optional): Custom Guzzle handler stack
Note: The healthCheck()
endpoint does not require authentication and will work without a valid token.
submitQueryJob(string $branchId, string $workspaceId, array $requestBody): array
getJobStatus(string $queryJobId): array
getJobResults(string $queryJobId, string $statementId): array
cancelJob(string $queryJobId, array $requestBody = []): array
healthCheck(): array
Run unit tests:
vendor/bin/phpunit tests/ClientTest.php
Functional tests require environment variables to be set:
TESTS_STORAGE_API_TOKEN
- Storage API authentication tokenTESTS_QUERY_API_URL
- Query Service API endpoint URLTESTS_STORAGE_API_URL
- Storage API endpoint URL
Run functional tests:
vendor/bin/phpunit tests/Functional/
Run all tests:
composer run tests
Run code style check:
composer run phpcs
Fix code style issues:
composer run phpcbf
Run static analysis:
composer run phpstan
Run all CI checks. Check Github Workflows for more details
composer run ci