PHP code example of justpilot / billomat-php-api

1. Go to this page and download the library: Download justpilot/billomat-php-api 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/ */

    

justpilot / billomat-php-api example snippets




declare(strict_types=1);

iceCreateOptions;
use Justpilot\Billomat\Api\InvoiceItemCreateOptions;
use Justpilot\Billomat\BillomatClient;
use Justpilot\Billomat\Model\Enum\InvoicePdfType;

$billomat = BillomatClient::create(
    billomatId: 'mycompany',
    apiKey: getenv('BILLOMAT_API_KEY'),
);

// 1) Rechnung als Entwurf anlegen
$item = new InvoiceItemCreateOptions(quantity: 8.0, unitPrice: 95.00);
$item->title = 'Konzeption';

$options = new InvoiceCreateOptions(clientId: 12345);
$options->title = 'Webentwicklung Mai 2026';
$options->addItem($item);

$invoice = $billomat->invoices->create($options);

// 2) Rechnung abschließen (vergibt Nummer und erzeugt PDF)
$billomat->invoices->complete($invoice->id);

// 3) PDF herunterladen
$pdf = $billomat->invoices->pdf($invoice->id, InvoicePdfType::SIGNED, rawPdf: true);
file_put_contents(sprintf('invoice-%d.pdf', $invoice->id), $pdf);

$billomat = BillomatClient::create(
    billomatId: 'mycompany',
    apiKey: '…',
    appId: null,        // optional, nur für eingetragene Drittanbieter-Apps
    appSecret: null,    // optional
    timeout: 10.0,      // Sekunden
    httpClient: null,   // optional eigener HttpClientInterface
);

use Justpilot\Billomat\BillomatClient;
use Justpilot\Billomat\Config\BillomatConfig;

$config = new BillomatConfig(
    billomatId: 'mycompany',
    apiKey: '…',
    timeout: 15.0,
);

$billomat = new BillomatClient($config);

// Auto-Pagination — lazy Generator, läuft über alle Seiten
foreach ($billomat->clients->iterateAll(['country_code' => 'DE']) as $client) {
    // …
}

// Eine Seite mit Metadaten
$result = $billomat->clients->listPage(['per_page' => 50, 'page' => 3]);
echo "Seite {$result->info->page} / " . ($result->info->totalPages() ?? '?');

use Justpilot\Billomat\BillomatClient;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpClient\RetryableHttpClient;
use Symfony\Component\HttpClient\TraceableHttpClient;

$inner = HttpClient::create(['max_duration' => 30.0]);
$decorated = new TraceableHttpClient(new RetryableHttpClient($inner));

$billomat = BillomatClient::create(
    billomatId: 'mycompany',
    apiKey: getenv('BILLOMAT_API_KEY'),
    httpClient: $decorated,
);
bash
composer