meraproject/vendor/amocrm/amocrm-api-library/examples/custom_field_groups_actions.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

59 lines
1.9 KiB
PHP
Raw 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\Helpers\EntityTypesInterface;
use AmoCRM\Collections\CustomFieldGroupsCollection;
use AmoCRM\Exceptions\AmoCRMApiException;
use AmoCRM\Models\CustomFieldGroupModel;
use League\OAuth2\Client\Token\AccessTokenInterface;
include_once __DIR__ . '/bootstrap.php';
$accessToken = getToken();
$apiClient->setAccessToken($accessToken)
->setAccountBaseDomain($accessToken->getValues()['baseDomain'])
->onAccessTokenRefresh(
function (AccessTokenInterface $accessToken, string $baseDomain) {
saveToken(
[
'accessToken' => $accessToken->getToken(),
'refreshToken' => $accessToken->getRefreshToken(),
'expires' => $accessToken->getExpires(),
'baseDomain' => $baseDomain,
]
);
}
);
//Сервис групп полей
try {
$customFieldGroupsService = $apiClient->customFieldGroups(EntityTypesInterface::LEADS);
} catch (AmoCRMApiException $e) {
printError($e);
die;
}
//Создадим группу полей
$customFieldGroupsCollection = new CustomFieldGroupsCollection();
$cfGroup = new CustomFieldGroupModel();
$cfGroup->setName('Группа полей');
$cfGroup->setSort(15);
$customFieldGroupsCollection->add($cfGroup);
try {
//Добавим группу
$customFieldGroupsCollection = $customFieldGroupsService->add($customFieldGroupsCollection);
//Получим объект группы и удалим его
$groupToDelete = $customFieldGroupsCollection->getBy('name', 'Группа полей');
$customFieldGroupsService->deleteOne($groupToDelete);
//Получим группы (это же пример :) )
$customFieldGroupsCollection = $customFieldGroupsService->get();
} catch (AmoCRMApiException $e) {
printError($e);
die;
}
var_dump($customFieldGroupsCollection);
die;