PHP code example of zitadel / client

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

    

zitadel / client example snippets


use \Zitadel\Client\Zitadel;

$zitadel = Zitadel::withPrivateKey("https://example.us1.zitadel.cloud", "path/to/jwt-key.json");

try {
    $response = $zitadel->users->userServiceAddHumanUser([
        'username' => 'john.doe',
        'profile'  => [
            'givenName'  => 'John',
            'familyName' => 'Doe'
        ],
        'email' => [
            'email' => '[email protected]'
        ]
    ]);
    echo "User created: " . print_r($response, true);
} catch (ApiException $e) {
    echo "Error: " . $e->getMessage();
}

use \Zitadel\Client\Zitadel;

$zitadel = Zitadel::withClientCredentials("https://example.us1.zitadel.cloud", "id", "secret");

try {
    $response = $zitadel->users->userServiceAddHumanUser([
        'username' => 'john.doe',
        'profile'  => [
            'givenName'  => 'John',
            'familyName' => 'Doe'
        ],
        'email' => [
            'email' => '[email protected]'
        ]
    ]);
    echo "User created: " . print_r($response, true);
} catch (ApiException $e) {
    echo "Error: " . $e->getMessage();
}

use \Zitadel\Client\Zitadel;

$zitadel = Zitadel::withAccessToken("https://example.us1.zitadel.cloud", "token");

try {
    $response = $zitadel->users->userServiceAddHumanUser([
        'username' => 'john.doe',
        'profile'  => [
            'givenName'  => 'John',
            'familyName' => 'Doe'
        ],
        'email' => [
            'email' => '[email protected]'
        ]
    ]);
    echo "User created: " . print_r($response, true);
} catch (ApiException $e) {
    echo "Error: " . $e->getMessage();
}

$zitadel = new Zitadel('your-zitadel-base-url', 'your-valid-token', fn($config) => $config->setDebug(true));