PHP code example of skriptfabrik / php-api-client

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

    

skriptfabrik / php-api-client example snippets




declare(strict_types=1);

$api = new Skriptfabrik\ApiClient\Api\AdminApi();

try {
    $result = $api->getAdminEntryPoint();
    print_r($result);
} catch (Exception $e) {
    echo 'Exception on fetching admin entry point: ', $e->getMessage(), PHP_EOL;
}



declare(strict_types=1);

$config = Skriptfabrik\ApiClient\Configuration::getDefaultConfiguration();
$config->setDebug(true);

$api = new Skriptfabrik\ApiClient\Api\AdminApi(
    // If you want to use a custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client(),
    $config
);

try {
    $result = $api->getAdminEntryPoint();
    print_r($result);
} catch (Exception $e) {
    echo 'Exception on fetching admin entry point: ', $e->getMessage(), PHP_EOL;
}



declare(strict_types=1);

ed Skriptfabrik\ApiClient\Api\AuthorizationApi $api;

    public function __construct(Skriptfabrik\ApiClient\Api\AuthorizationApi $api)
    {
        $this->api = $api;
    }

    /**
     * @throws Skriptfabrik\ApiClient\ApiException
     */
    public function createAccessToken(string $username, string $password): string
    {
        $request = new Skriptfabrik\ApiClient\Model\CreateAccessTokenRequest([
            'username' => $username,
            'password' => $password,
        ]);

        return $this->api->createAccessToken($request)->getToken();
    }
}



declare(strict_types=1);

$auth = new AuthService(
    new Skriptfabrik\ApiClient\Api\AuthorizationApi()
);

try {
    $accessToken = $auth->createAccessToken('[email protected]', 's3Cur3_Pa$$w0rd');
} catch (Exception $e) {
    echo 'Authorization failed: ', $e->getMessage(), PHP_EOL;
    exit;
}

$config = Skriptfabrik\ApiClient\Configuration::getDefaultConfiguration();
$config->setAccessToken($accessToken);

$api = new Skriptfabrik\ApiClient\Api\UserApi(null, $config);

try {
    $result = $api->getUserCollection();
    print_r($result);
} catch (Exception $e) {
    echo 'Exception on fetching admin entry point: ', $e->getMessage(), PHP_EOL;
}
bash
composer