метод REST
scope: im
im.v2.Event.subscribe
Подписаться на события
Описание
Метод im.v2.Event.subscribe подписывает текущего пользователя на запись событий. После подписки события сообщений записываются в лог и становятся доступными через im.v2.Event.get.
Метод идемпотентный: повторный вызов безопасен и не приводит к ошибке.
Примеры запроса
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/im.v2.Event.subscribe
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"auth":"**put_access_token_here**"}' \
https://**put_your_bitrix24_address**/rest/im.v2.Event.subscribe
try {
const response = await $b24.callMethod('im.v2.Event.subscribe', {});
const { result } = response.getData();
console.log('result:', result);
} catch (error) {
console.error('Error:', error);
}
from b24pysdk.errors import BitrixAPIError, BitrixSDKException
try:
bitrix_response = client.im.v2.event.subscribe().response
result = bitrix_response.result
print(result)
except BitrixAPIError as error:
print(
"Ошибка Bitrix API",
f"error: {error.error}",
f"error_description: {error.error_description}",
sep="\n",
)
except BitrixSDKException as error:
print(f"Ошибка Bitrix SDK: {error.message}")
except Exception as error:
print(f"Непредвиденная ошибка: {error}")
try {
$response = $b24Service
->core
->call(
'im.v2.Event.subscribe',
[]
);
$result = $response
->getResponseData()
->getResult();
echo 'result: ' . print_r($result, true);
} catch (Throwable $exception) {
error_log($exception->getMessage());
echo 'Error: ' . $exception->getMessage();
}
BX24.callMethod(
'im.v2.Event.subscribe',
{},
function(result) {
if (result.error()) {
console.error(result.error().ex);
} else {
console.log(result.data());
}
}
);
require_once('crest.php');
$result = CRest::call('im.v2.Event.subscribe', []);
if (!empty($result['error'])) {
echo 'Error: ' . $result['error_description'];
} else {
echo 'Subscribed';
}
// client и ctx уже созданы — см. раздел «SDK для Go»
res, err := client.Core().Call(ctx, "im.v2.Event.subscribe", nil)
if err != nil {
return fmt.Errorf("im.v2.Event.subscribe: %w", err)
}
var ok bool
if err := json.Unmarshal(res.Result, &ok); err != nil {
return fmt.Errorf("разбор ответа: %w", err)
}
fmt.Println("выполнено:", ok)
Ответ
HTTP-статус: 200
{
"result": true,
"time": {
"start": 1728626400.123,
"finish": 1728626400.234,
"duration": 0.111,
"processing": 0.045,
"date_start": "2024-10-11T10:00:00+03:00",
"date_finish": "2024-10-11T10:00:00+03:00"
}
}

