Skip to content

Change an employee's role

POSThttps://gptunnel.ru/api/v1/access/changeRole

Assign a role to each employee by login. Send an array of up to 25 { login, role } pairs. Each item is processed independently, so a failed item does not affect the rest. If a login appears more than once, the first entry is used.

The main organization roles in descending order are owner, admin, and member.

The manager role is scoped to a team. In the dashboard, managers can add or remove members of their own teams and configure their access. Those rights do not extend to other teams. A manager key cannot change roles and receives HTTP 403. Through the API, managers can only configure access and limits for their own teams and their members, and can only make rules stricter. See Access management. Owners and admins can assign the manager role and change a manager’s role.

Role changes use the permissions of the person who created the API key. The key can act on employees with a role equal to or lower than the creator’s role. It cannot change the creator’s own role.

Key creator’s role Whose role it can change Roles it can assign
owner owner, admin, member, manager admin / member / manager
admin admin, member, manager admin / member / manager
member, manager none —
  • A login with a higher role returns forbidden. An owner can change another owner’s role, and an admin can change another admin’s role.
  • The key creator’s own login returns forbidden.
  • An item requesting role = owner returns forbidden for any key. The remaining items are still processed. Ownership can be transferred only in the web interface.
  • Assigning the same role again is idempotent and is counted in changed.

Request headers

ParameterTypeDescription
Authorization*stringAPI key

Request parameters

ParameterTypeDescription
items*object[]Array of 1–25 items. Each item contains { login, role }.
items[].login*stringEmployee login
items[].role*stringAssignable roles: admin, member, or manager. The schema accepts owner, but that item returns forbidden.

In response: changed — number of processed logins, including those already assigned the requested role, failed - the number of failed items, failedLogins - A list of errors (cause and explanation for each).

Error reasons in failedLogins:

Error reasons

ParameterTypeDescription
not_foundstringNo employee in the organization has this login
forbiddenstringThe target role is higher than the key creator’s role, the target login is the creator’s own login, or the requested role is owner
errorstringAn unexpected error occurred while processing this employee

Set GPTUNNEL_API_KEY and replace the placeholders with values for your organization.

import json
import os
from urllib.request import Request, urlopen
key = os.environ.get("GPTUNNEL_API_KEY")
if not key:
raise SystemExit("Set GPTUNNEL_API_KEY")
body = {
"items": [
{
"login": "ivanov",
"role": "admin"
},
{
"login": "petrov",
"role": "member"
}
]
}
request = Request(
"https://gptunnel.ru/api/v1/access/changeRole",
method="POST",
headers={
"Authorization": key,
"Content-Type": "application/json",
},
data=json.dumps(body).encode("utf-8"),
)
with urlopen(request, timeout=30) as response:
print(json.load(response))
{
"code": 0,
"changed": 1,
"failed": 1,
"failedLogins": [
{
"login": "petrov",
"reason": "not_found",
"message": "Employee not found in the organization."
}
]
}