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->addHumanUser((new UserServiceAddHumanUserRequest())
        ->setUsername('john.doe')
        ->setProfile(
            (new UserServiceSetHumanProfile())
                ->setGivenName('John')
                ->setFamilyName('Doe')
        )
        ->setEmail(
            (new UserServiceSetHumanEmail())
                ->setEmail('[email protected]')
        ));
    echo "User created: " . print_r($response, true);
} catch (ApiException $e) {
    echo "Error: " . $e->getMessage();
}

use Zitadel\Client\Zitadel;
use Zitadel\Client\Model\UserServiceAddHumanUserRequest;
use Zitadel\Client\Model\UserServiceSetHumanProfile;
use Zitadel\Client\Model\UserServiceSetHumanEmail;

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

try {
    $response = $zitadel->users->addHumanUser((new UserServiceAddHumanUserRequest())
        ->setUsername('john.doe')
        ->setProfile(
            (new UserServiceSetHumanProfile())
                ->setGivenName('John')
                ->setFamilyName('Doe')
        )
        ->setEmail(
            (new UserServiceSetHumanEmail())
                ->setEmail('[email protected]')
        ));
    echo "User created: " . print_r($response, true);
} catch (ApiException $e) {
    echo "Error: " . $e->getMessage();
}

use Zitadel\Client\Zitadel;
use Zitadel\Client\Model\UserServiceAddHumanUserRequest;
use Zitadel\Client\Model\UserServiceSetHumanProfile;
use Zitadel\Client\Model\UserServiceSetHumanEmail;

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

try {
    $response = $zitadel->users->addHumanUser(
        (new UserServiceAddHumanUserRequest())
            ->setUsername('john.doe')
            ->setProfile(
                (new UserServiceSetHumanProfile())
                    ->setGivenName('John')
                    ->setFamilyName('Doe')
            )
            ->setEmail(
                (new UserServiceSetHumanEmail())
                    ->setEmail('[email protected]')
            )
    );
    echo "User created: " . print_r($response, true);
} catch (ApiException $e) {
    echo "Error: " . $e->getMessage();
}

use Zitadel\Client\Zitadel;
use Zitadel\Client\TransportOptions;

$options = new TransportOptions(insecure: true);

$zitadel = Zitadel::withClientCredentials(
    'https://your-instance.zitadel.cloud',
    'client-id',
    'client-secret',
    $options,
);

use Zitadel\Client\Zitadel;
use Zitadel\Client\TransportOptions;

$options = new TransportOptions(caCertPath: '/path/to/ca.pem');

$zitadel = Zitadel::withClientCredentials(
    'https://your-instance.zitadel.cloud',
    'client-id',
    'client-secret',
    $options,
);

use Zitadel\Client\Zitadel;
use Zitadel\Client\TransportOptions;

$options = new TransportOptions(
    defaultHeaders: ['X-Custom-Header' => 'my-value'],
);

$zitadel = Zitadel::withClientCredentials(
    'https://your-instance.zitadel.cloud',
    'client-id',
    'client-secret',
    $options,
);

use Zitadel\Client\Zitadel;
use Zitadel\Client\TransportOptions;

$options = new TransportOptions(proxyUrl: 'http://user:pass@proxy:8080');

$zitadel = Zitadel::withClientCredentials(
    'https://your-instance.zitadel.cloud',
    'client-id',
    'client-secret',
    $options,
);