meraproject/vendor/amocrm/amocrm-api-library/examples/get_account_subdomain.php
keboss-m 5c21d25d45 Initial commit: Merakomis portal, Docker stack and user-reader API.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-24 11:04:05 +03:00

35 lines
1.3 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
use AmoCRM\Exceptions\AmoCRMApiException;
include_once __DIR__ . '/bootstrap.php';
$accessToken = getToken();
try {
/**
* В случае потери/смены субдомена аккаунта, мы можем его получить с помощью access_token
* Сделав запрос на www.amocrm.ru/oauth2/account/subdomain
*
* Получим модель с информацией о домене аккаунта по access_token
* Подробнее: @see AccountDomainModel
*
* Запрос уходит на www.amocrm.ru/oauth2/account/subdomain
* С Authorization: Bearer {access_token}
*
* @example curl 'https://www.amocrm.ru/oauth2/account/subdomain' -H 'Authorization: Bearer {access_token}'
*/
$accountDomainModel = $apiClient->getOAuthClient()
->getAccountDomain($accessToken);
var_dump($accountDomainModel->toArray());
// Возьмём из полученной модели текущий subdomain аккаунта и засетим наш субдомен аккаунта в апи клиенте
$apiClient->setAccountBaseDomain($accountDomainModel->getSubdomain());
var_dump($apiClient->getAccountBaseDomain());
} catch (AmoCRMApiException $e) {
printError($e);
die;
}