PHP code example of virtuallast / confluence-v2-php-client

1. Go to this page and download the library: Download virtuallast/confluence-v2-php-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

virtuallast / confluence-v2-php-client example snippets


use VirtualLast\ConfluenceV2\Configuration;
use VirtualLast\ConfluenceV2\ConfluenceClient;

$client = ConfluenceClient::create(
    new Configuration(
        baseUrl: 'https://your-company.atlassian.net',
        email: '[email protected]',
        apiToken: $_ENV['CONFLUENCE_API_TOKEN'],
    ),
);

$page = $client->pages()->getPageById('123456');

echo $page->getTitle();

$pages = $client->pages()->getPages([
    'space-id' => ['12345'],
    'limit' => 50,
]);

foreach ($pages->results as $page) {
    echo $page->getTitle(), PHP_EOL;
}

foreach ($client->pages()->iteratePages([
    'limit' => 50,
]) as $page) {
    echo $page->getTitle(), PHP_EOL;
}

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);

$client = ConfluenceClient::create(
    $configuration,
    $psr18Client,
    $psr17RequestFactory,
    $psr17StreamFactory,
);
bash
php bin/console confluence:update-spec
bash
php bin/console confluence:generate