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\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\Zitadel;
use Zitadel\Client\Model\UserServiceAddHumanUserRequest;
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();
}