virtuallast / confluence-v2-php-client
A typed PHP client for the Confluence Cloud REST API v2.
Package info
github.com/virtualLast/confluence-v2-php-client
pkg:composer/virtuallast/confluence-v2-php-client
Requires
- php: ^8.3
- ext-json: *
- jane-php/open-api-runtime: ^7.0
- php-http/client-common: ^2.7
- php-http/discovery: ^1.20
- psr/http-client: ^1.0
- psr/http-factory: ^1.1
- psr/http-message: ^2.0
- symfony/serializer: ^7.4 || ^8.0
Requires (Dev)
- jane-php/open-api-3: ^7.0
- nyholm/psr7: ^1.8
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5 || ^12.0
- symfony/console: ^7.4 || ^8.0
- symfony/http-client: ^7.4 || ^8.0
- symfony/process: ^7.4 || ^8.0
Suggests
- nyholm/psr7: Recommended PSR-7 and PSR-17 implementation.
- symfony/http-client: Recommended PSR-18 HTTP transport.
README
A modern, strongly typed PHP client for the Atlassian Confluence Cloud REST API v2.
Generated directly from Atlassian's official OpenAPI specification, the library provides complete API coverage while remaining PSR-18 compatible, allowing it to work with Symfony HttpClient, Guzzle, HTTPlug-compatible clients, and other PSR implementations.
Features
- Complete Confluence Cloud REST API v2 coverage
- Generated from Atlassian's official OpenAPI specification
- Strongly typed request and response models
- PSR-18 HTTP client support
- PSR-17 request and stream factories
- Lazy pagination helpers
- No framework dependency
- PHP 8.3+
Installation
composer require virtuallast/confluence-v2-php-client \
symfony/http-client \
nyholm/psr7
The package depends only on PSR interfaces. Any PSR-18 client and PSR-17 implementation may be used.
Quick Start
use VirtualLast\ConfluenceV2\Configuration; use VirtualLast\ConfluenceV2\ConfluenceClient; $client = ConfluenceClient::create( new Configuration( baseUrl: 'https://your-company.atlassian.net', email: 'confluence-user@example.com', apiToken: $_ENV['CONFLUENCE_API_TOKEN'], ), ); $page = $client->pages()->getPageById('123456'); echo $page->getTitle();
Listing pages
$pages = $client->pages()->getPages([ 'space-id' => ['12345'], 'limit' => 50, ]); foreach ($pages->results as $page) { echo $page->getTitle(), PHP_EOL; }
Automatic pagination
Every paginated endpoint also exposes an iterator.
foreach ($client->pages()->iteratePages([ 'limit' => 50, ]) as $page) { echo $page->getTitle(), PHP_EOL; }
Pagination follows Confluence cursor links automatically while validating that the next page remains on the configured Confluence instance.
Creating resources
Write operations use generated request models.
use VirtualLast\ConfluenceV2\Generated\Model\PagesPostBody; use VirtualLast\ConfluenceV2\Generated\Model\PageBodyWrite; $body = (new PageBodyWrite()) ->setRepresentation('storage') ->setValue('<p>Hello from PHP</p>'); $request = (new PagesPostBody()) ->setSpaceId('12345') ->setStatus('current') ->setTitle('Generated page') ->setBody($body); $page = $client->pages()->createPage($request);
Configuration
The supplied baseUrl should be the Confluence site root, for example:
https://company.atlassian.net
The client automatically targets:
/wiki/api/v2
Authentication uses Atlassian email address and API token via HTTP Basic Authentication.
API tokens are automatically redacted from exception messages and debugging output.
Dependency Injection
Applications using a dependency injection container can provide their own PSR services.
$client = ConfluenceClient::create( $configuration, $psr18Client, $psr17RequestFactory, $psr17StreamFactory, );
If omitted, php-http/discovery locates suitable implementations automatically.
Error handling
- HTTP responses outside the successful range throw
ApiException. - Transport failures throw
TransportException.
The library deliberately performs no retries. Retry behaviour should be configured by the injected HTTP client.
Supported APIs
The client exposes resource APIs including:
- Pages
- Spaces
- Attachments
- Comments
- Users
- Blog Posts
…and every other resource defined in the Confluence Cloud REST API v2 specification.
Maintaining the generated client
The OpenAPI specification is committed to the repository together with all generated source code.
To update the specification:
php bin/console confluence:update-spec
To regenerate the client:
php bin/console confluence:generate
Equivalent Composer aliases are available:
composer update-spec composer generate composer run validate
Generated files should never be edited manually.
License
MIT