Upload a user's avatar

This endpoint is only available to organization administrators.

POST https://orientir.chat.lgprk.ru/api/v1/users/{email}/avatar

Upload a new profile picture for another user in the organization, identified by email. This endpoint is available to organization administrators, including bots with the administrator role.

The email may be the user's real delivery_email (if the requester is allowed to see it) or the dummy address user{id}@{realm.host}. This follows the same lookup rules as GET /users/{email}.

Administrators can change a user's avatar even if avatar changes are disabled for the organization.

Changes: New in Zulip 11.0 (feature level 422).

Usage examples

#!/usr/bin/env python

import zulip

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

# Upload a new avatar for another user. Requires administrator privileges.
with open(avatar_path, "rb") as fp:
    result = client.call_endpoint(
        url=f"/users/{email}/avatar",
        method="POST",
        files=[fp],
    )
print(result)

curl -sSX POST https://orientir.chat.lgprk.ru/api/v1/users/hamlet@zulip.com/avatar \
    -u BOT_EMAIL_ADDRESS:BOT_API_KEY \
    -F filename=@/path/to/avatar.png

Parameters

email string required in path

Example: "hamlet@zulip.com"

The email address of the user whose avatar should be changed. Two forms are supported:

  • The real email address of the user (delivery_email). The lookup will succeed if and only if the user exists and their email address visibility setting permits the client to see it.

  • The dummy Zulip API email address of the form user{user_id}@{realm_host}.


As described above, the image file to upload must be provided in the request's body.

Maximum file size

The maximum file size for uploads can be configured by the administrator of the Zulip server by setting MAX_AVATAR_FILE_SIZE_MIB in the server's settings. MAX_AVATAR_FILE_SIZE_MIB defaults to 5MB.

Response

Return values

  • avatar_url: string

    The URL of the user's new avatar.

Example response(s)

Changes: As of Zulip 7.0 (feature level 167), if any parameters sent in the request are not supported by this endpoint, a successful JSON response will include an ignored_parameters_unsupported array.

A typical successful JSON response may look like:

{
    "avatar_url": "/user_avatars/1/a32c06fab3bfb4858342da1d98787e9292be235d.png?version=2",
    "msg": "",
    "result": "success"
}

An example JSON error response when the requester is not an organization administrator:

{
    "code": "UNAUTHORIZED_PRINCIPAL",
    "msg": "Must be an organization administrator",
    "result": "error"
}

An example JSON error response when the request does not contain exactly one image file:

{
    "code": "BAD_REQUEST",
    "msg": "You must upload exactly one avatar.",
    "result": "error"
}

An example JSON error response when the target user does not exist:

{
    "code": "BAD_REQUEST",
    "msg": "No such user",
    "result": "error"
}