user.option.get
Получить пользовательские данные, привязанные к приложению
Описание
Метод user.option.get получает пользовательские данные, привязанные к приложению. Если ничего не подать на вход, то вернет все записанные через user.option.set свойства.
Параметры
option
string
необязательный
Один из ключей, сохраненных методом user.option.set.
Если параметр не передан, метод вернет все сохраненные настройки текущего пользователя
Примеры запроса
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"option": "data"
}' \
https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/user.option.get
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{}' \
https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/user.option.get
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"option": "data",
"auth": "**put_access_token_here**"
}' \
https://**put_your_bitrix24_address**/rest/user.option.get
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{}' \
https://**put_your_bitrix24_address**/rest/user.option.get
// This snippet is an ES module: top-level await requires type="module" or a bundler.
// $b24 is an already-initialized SDK instance (see the SDK "Get started" guide).
import { Text } from '@bitrix24/b24jssdk'
import type { B24Frame } from '@bitrix24/b24jssdk'
declare const $b24: B24Frame
// Shape of the payload returned in result (match the "response handling" section of the page)
type UserOptionResult = Record<string, string>
// Example 1: get a specific option by key
try {
const response = await $b24.actions.v2.call.make<UserOptionResult>({
method: 'user.option.get',
params: {
option: 'data',
},
requestId: Text.getUuidRfc4122()
})
// The payload is available only on a successful response
if (!response.isSuccess) {
console.error(response.getErrorMessages().join('; '))
} else {
const result = response.getData()!.result
console.info('Option value:', result['data'])
}
} catch (error) {
// Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
console.error(error)
}
// Example 2: get all options (no parameters)
try {
const response = await $b24.actions.v2.call.make<UserOptionResult>({
method: 'user.option.get',
params: {},
requestId: Text.getUuidRfc4122()
})
// The payload is available only on a successful response
if (!response.isSuccess) {
console.error(response.getErrorMessages().join('; '))
} else {
const result = response.getData()!.result
console.info('All options:', Object.keys(result), result)
}
} catch (error) {
// Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
console.error(error)
}
<!-- Load the SDK (UMD build); it is exposed as the global B24Js -->
<script src="https://unpkg.com/@bitrix24/b24jssdk@1/dist/umd/index.min.js"></script>
<script>
async function getUserOptions() {
try {
// Initialize the SDK inside a Bitrix24 frame
const $b24 = await B24Js.initializeB24Frame()
// Example 1: get a specific option by key
const response1 = await $b24.actions.v2.call.make({
method: 'user.option.get',
params: {
option: 'data',
},
requestId: B24Js.Text.getUuidRfc4122()
})
// The payload is available only on a successful response
if (!response1.isSuccess) {
console.error(response1.getErrorMessages().join('; '))
return
}
const result1 = response1.getData().result
console.info('Option value:', result1['data'])
// Example 2: get all options (no parameters)
const response2 = await $b24.actions.v2.call.make({
method: 'user.option.get',
params: {},
requestId: B24Js.Text.getUuidRfc4122()
})
// The payload is available only on a successful response
if (!response2.isSuccess) {
console.error(response2.getErrorMessages().join('; '))
return
}
const result2 = response2.getData().result
console.info('All options:', Object.keys(result2), result2)
} catch (error) {
// Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
console.error(error)
}
}
document.addEventListener('DOMContentLoaded', getUserOptions)
</script>
from b24pysdk.errors import BitrixAPIError, BitrixSDKException
try:
bitrix_response = client.user.option.get(
option="data",
).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}")
from b24pysdk.errors import BitrixAPIError, BitrixSDKException
try:
bitrix_response = client.user.option.get().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}")
require_once('crest.php');
$result = CRest::call(
'user.option.get',
[
'option' => 'data'
]
);
echo '<PRE>';
print_r($result);
echo '</PRE>';
require_once('crest.php');
$result = CRest::call(
'user.option.get',
[]
);
echo '<PRE>';
print_r($result);
echo '</PRE>';
// client и ctx уже созданы — см. раздел «SDK для Go»
res, err := client.Core().Call(ctx, "user.option.get", b24.Params{
"option": "data",
}, b24.WithIdempotent())
if err != nil {
return fmt.Errorf("user.option.get: %w", err)
}
// Ответ приходит как json.RawMessage — разберите его
// в структуру под форму ответа, показанную ниже на этой странице.
fmt.Printf("%s\n", res.Result)
Ответ
HTTP-статус: 200
{
"result": {
"data": "value",
"data2": "value2"
},
"time": {
"start": 1722001311.94644,
"finish": 1722001311.98622,
"duration": 0.0397801399230957,
"processing": 0.000041961669921875,
"date_start": "2024-07-26T13:41:51+00:00",
"date_finish": "2024-07-26T13:41:51+00:00",
"operating": 0
}
}
Возвращаемые данные
result
object
Зависит от параметра option:
- параметр не передан — объект, где ключ это название настройки, а значение это сохраненное значение. Если настроек нет, объект пустой
- параметр передан — сохраненное значение ключа
- параметр передан, но такого ключа нет —
null
time
time
Информация о времени выполнения запроса
Обработка ошибок
HTTP-статус: 400
{
"error":"AccessException",
"error_description":"Application context required"
}
| Код | Описание | Значение |
|---|---|---|
AccessException |
Application context required | Метод вызван вне контекста приложения |
AccessException |
User authorization required | Пользователь не авторизован |

