PHP code example of tigusigalpa / yandex-cloud-client-php
1. Go to this page and download the library: Download tigusigalpa/yandex-cloud-client-php 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/ */
tigusigalpa / yandex-cloud-client-php example snippets
use Tigusigalpa\YandexCloudClient\YandexCloudClient;
// Инициализация клиента
$client = new YandexCloudClient('ваш_oauth_токен');
// Список всех организаций
$organizations = $client->organizations()->list();
// Список облаков в организации
$clouds = $client->clouds()->list(organizationId: 'org_id');
// Создать новый каталог
$folder = $client->folders()->create(
cloudId: 'cloud_id',
name: 'Мой каталог',
description: 'Создан через API'
);
// Получить пользователя по ID
$user = $client->userAccounts()->get('user_account_id');
// Получить пользователя по логину Yandex Passport (для получения ID)
$user = $client->yandexPassportUserAccounts()->getByLogin('username');
// Возвращает: ['id' => 'user_id', 'login' => 'username', ...]
// Использовать ID для назначения ролей
$userId = $user['id'];
$client->folders()->addRole(
folderId: 'folder_id',
subjectId: $userId,
roleId: 'editor',
subjectType: 'userAccount'
);
// Список API ключей для сервисного аккаунта
$keys = $client->apiKeys()->list(
serviceAccountId: 'service_account_id',
pageSize: 100
);
// Получить API ключ
$key = $client->apiKeys()->get('api_key_id');
// Создать API ключ (secret показывается только один раз!)
$key = $client->apiKeys()->create(
serviceAccountId: 'service_account_id',
description: 'API ключ для продакшна'
);
// Сохраните $key['secret'] немедленно - он больше не будет показан!
// Обновить API ключ
$key = $client->apiKeys()->update('api_key_id', [
'description' => 'Обновлённое описание',
]);
// Удалить API ключ
$result = $client->apiKeys()->delete('api_key_id');