PHP code example of daniel-jorg-schuppelius / datev-php-sdk

1. Go to this page and download the library: Download daniel-jorg-schuppelius/datev-php-sdk 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/ */

    

daniel-jorg-schuppelius / datev-php-sdk example snippets


use APIToolkit\API\Authentication\BasicAuthentication;
use Datev\API\Desktop\Client;

$authentication = new BasicAuthentication('Benutzer', 'Passwort');
$client = new Client($authentication, 'https://127.0.0.1:58452');

use APIToolkit\API\Authentication\BearerAuthentication;
use Datev\API\Desktop\Client;

$authentication = new BearerAuthentication(
    'your-api-key',
    ['X-Datev-Client-ID' => 'your-client-id']
);
$client = new Client($authentication, 'https://127.0.0.1:58452');

use APIToolkit\API\Authentication\BasicAuthentication;
use Datev\API\Desktop\Client;
use Datev\API\Desktop\Endpoints\Accounting\ClientsEndpoint;

$client = new Client(new BasicAuthentication('user', 'password'));
$endpoint = new ClientsEndpoint($client);

// Alle Mandanten abrufen
$clients = $endpoint->get();

// Einzelnen Mandanten abrufen
$singleClient = $endpoint->get(id: $clientId);

use APIToolkit\API\Authentication\BasicAuthentication;
use Datev\API\Desktop\Client;
use Datev\API\Desktop\Endpoints\Payroll\EmployeesEndpoint;

$client = new Client(new BasicAuthentication('user', 'password'));
$endpoint = new EmployeesEndpoint($client);

// Mitarbeiter mit Referenzdatum abrufen (erforderlich für HR-Endpoints)
$employees = $endpoint->get(referenceDate: new DateTime('2024-01-01'));

use APIToolkit\API\Authentication\BasicAuthentication;
use Datev\API\Desktop\Client;
use Datev\API\Desktop\Endpoints\Diagnostics\EchoEndpoint;

$client = new Client(new BasicAuthentication('user', 'password'));
$echoEndpoint = new EchoEndpoint($client);

$response = $echoEndpoint->get();

use APIToolkit\API\Authentication\BearerAuthentication;
use Datev\API\Online\{Client, OnlineService};

$client = new Client(
    OnlineService::AccountingClients,
    new BearerAuthentication($accessToken),
    'meine-datev-client-id',   // X-DATEV-Client-Id
    sandbox: true               // /platform-sandbox statt /platform
);

// ApiKey-only-Dienste (Kassenarchiv, Health-Endpunkte):
$cashClient = Client::forApiKey(OnlineService::CashRegister, $clientId, $clientSecret);

use Datev\API\Online\Endpoints\AccountingClients\ClientsEndpoint;
use Datev\API\Online\Endpoints\AccountingDocuments\DocumentsEndpoint;

// Mandantenliste inkl. freigeschalteter Datenservices (OData-Paging)
$clients = (new ClientsEndpoint($client))->searchPage(['top' => 100]);
echo $clients->getTotalItems();

// Beleg hochladen (Belegbilderservice, multipart)
$documents = new DocumentsEndpoint($documentsClient, '29098-55003');
$document = $documents->upload(
    file_get_contents('rechnung.pdf'),
    'rechnung.pdf',
    ['document_type' => 'Rechnungseingang', 'note' => 'Juli 2026']
);

use Datev\API\Online\Endpoints\AccountingExtfFiles\ExtfFilesEndpoint;
use Datev\Enums\Online\ExtfJobResult;

$extf = new ExtfFilesEndpoint($extfClient, '29098-100');   // Verbundnummer
$jobLocation = $extf->import($extfContent, 'EXTF_Buchungsstapel.csv');
$job = $extf->waitForImport($jobLocation);                  // pollt bis succeeded/failed

if ($job?->getResult() === ExtfJobResult::Failed) {
    echo $job->getValidationDetails()?->getDetail();
}
bash
php tools/OpenApiCoverageAnalyzer.php