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): arraygetJobStatus(string $queryJobId): arraygetJobResults(string $queryJobId, string $statementId): arraycancelJob(string $queryJobId, array $requestBody = []): arrayhealthCheck(): array
Run unit tests:
vendor/bin/phpunit tests/ClientTest.phpFunctional 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 testsRun code style check:
composer run phpcsFix code style issues:
composer run phpcbfRun static analysis:
composer run phpstanRun all CI checks. Check Github Workflows for more details
composer run ci