Skip to content

virtualLast/confluence-v2-php-client

Repository files navigation

Confluence REST API v2 PHP Client

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages