Часть технических описаний пока доступна на английском языке.

Update a custom profile field

Этот метод API доступен только администраторам организации.

PATCH https://z.u1v.ru/api/v1/realm/profile_fields/{field_id}

Update the configuration of a custom profile field in the user's organization.

The type of a custom profile field cannot be changed.

At most, 2 custom profile fields can have display_in_profile_summary set to true in an organization.

For custom profile fields with type 7 (External account) that use one of Zulip's configured default external account providers (e.g., GitHub, LinkedIn, etc.), the field's name, hint, and field_data cannot be changed, and attempting to do so will return an error.

Changes: Before Zulip 9.0 (feature level 252), the name, hint, field_data, required and display_in_profile_summary parameters were all required in every request, even when their values were unchanged.

Примеры запросов

#!/usr/bin/env python

import pero

# The user for this perorc file must be an organization administrator
client = pero.Client(config_file="~/.perorc-admin")

# Update a custom profile field in the user's organization.
request = {"name": "Cell", "hint": "Contact number."}
result = client.call_endpoint(
    url=f"/realm/profile_fields/{field_id}", method="PATCH", request=request
)
print(result)

Параметр -u задаёт учётные данные для HTTP-аутентификации Basic. Как получить их для пользователя или бота, описано в разделе о заголовке Authorization.

curl -sSX PATCH https://z.u1v.ru/api/v1/realm/profile_fields/4 \
    -u EMAIL_ADDRESS:API_KEY \
    --data-urlencode 'name=Programming language' \
    --data-urlencode 'hint=Your favorite programming language.' \
    --data-urlencode 'field_data={"java": {"order": "2", "text": "Java"}, "python": {"order": "1", "text": "Python"}}' \
    --data-urlencode display_in_profile_summary=true \
    --data-urlencode required=true \
    --data-urlencode editable_by_user=true \
    --data-urlencode use_for_user_matching=false

Параметры

field_id integer обязательно в пути

Пример: 4

The ID of the target custom profile field.


name string необязательно

Пример: "Programming language"

The name of the custom profile field, which appears both in the user-facing settings UI for configuring the custom profile fields and in the UI displaying a user's profile.


hint string необязательно

Пример: "Your favorite programming language."

Подсказка для дополнительного поля профиля, отображаемая в интерфейсе настроек таких полей.


field_data object необязательно

Пример: {"python": {"text": "Python", "order": "1"}, "java": {"text": "Java", "order": "2"}}

Field types 3 (Dropdown) and 7 (External account) support storing additional configuration for the field type in the field_data attribute.

For field type 3 (Dropdown), this attribute is a JSON object defining the choices and the order they will be displayed in the dropdown UI for individual users to select an option.

The interface for field type 7 is not yet stabilized.

See profile field types or the field_type parameter for what each field type number means.


display_in_profile_summary boolean необязательно

Пример: true

Whether clients should display this profile field in the summary section of a user's profile (or in a more easily accessible "small profile").

At most 2 profile fields may have this property be true in a given organization.

The "Users" profile field is not supported, but that is likely to be temporary.

Changes: Before Zulip 12.0 (feature level 476), the "Paragraph" field type was not supported.

New in Zulip 6.0 (feature level 146).


required boolean необязательно

Пример: true

Сделал ли администратор организации это поле профиля обязательным.

Обязательность поля можно изменить, поэтому клиентам нельзя предполагать, что обязательное дополнительное поле профиля всегда заполнено. Веб-приложение показывает заметный баннер пользователю, который не заполнил обязательное поле.

Изменения: Добавлено в Zulip 9.0 (уровень возможностей 244).


editable_by_user boolean необязательно

Пример: true

Могут ли обычные пользователи редактировать это поле в собственном профиле.

Администраторы организации могут редактировать дополнительные поля профиля любого пользователя независимо от этой настройки.

Изменения: Добавлено в Zulip 10.0 (уровень возможностей 296).


use_for_user_matching boolean необязательно

Пример: false

Следует ли использовать это дополнительное поле профиля для поиска пользователей в подсказках автодополнения. Разрешено только для типов полей профиля «Короткий текст» и «Внешний аккаунт».

Поле включается в ответ только при значении true.

Изменения: Добавлено в Zulip 12.0 (уровень возможностей 455).


Ответ

Примеры ответов

Изменения: Начиная с Zulip 7.0 (уровень возможностей 167), успешный JSON-ответ содержит массив ignored_parameters_unsupported, если запрос включает параметры, которые метод не поддерживает.

Пример успешного JSON-ответа:

{
    "msg": "",
    "result": "success"
}

A typical failed JSON response for when there is no custom profile field with the requested ID:

{
    "code": "BAD_REQUEST",
    "msg": "Field id 4 not found.",
    "result": "error"
}

A typical failed JSON response for when another custom profile field already uses the requested name:

{
    "code": "BAD_REQUEST",
    "msg": "A field with that label already exists.",
    "result": "error"
}

A typical failed JSON response for when setting display_in_profile_summary to true would exceed the organization's limit of 2 such fields:

{
    "code": "BAD_REQUEST",
    "msg": "Only 2 custom profile fields can be displayed in the profile summary.",
    "result": "error"
}

A typical failed JSON response for when attempting to change the name, hint, or field_data of a default external account field:

{
    "code": "BAD_REQUEST",
    "msg": "Default custom field cannot be updated.",
    "result": "error"
}