Change an employee's role
Change of Role
Section titled “Change of Role”https://gptunnel.ru/api/v1/access/changeRoleAssign 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.
Roles and permissions
Section titled “Roles and permissions”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 = ownerreturnsforbiddenfor 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
| Parameter | Type | Description |
|---|---|---|
Authorization* | string | API key |
Request parameters
| Parameter | Type | Description |
|---|---|---|
items* | object[] | Array of 1–25 items. Each item contains { login, role }. |
items[].login* | string | Employee login |
items[].role* | string | Assignable 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
| Parameter | Type | Description |
|---|---|---|
not_found | string | No employee in the organization has this login |
forbidden | string | The 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 |
error | string | An unexpected error occurred while processing this employee |
Example request
Section titled “Example request”Set GPTUNNEL_API_KEY and replace the placeholders with values for your organization.
import jsonimport osfrom 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))curl --request POST \ --url 'https://gptunnel.ru/api/v1/access/changeRole' \ --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \ --header 'Content-Type: application/json' \ --data '{ "items": [ { "login": "ivanov", "role": "admin" }, { "login": "petrov", "role": "member" } ]}'const key = process.env.GPTUNNEL_API_KEYif (!key) throw new Error("Set GPTUNNEL_API_KEY")
const body = { "items": [ { "login": "ivanov", "role": "admin" }, { "login": "petrov", "role": "member" } ]}const response = await fetch("https://gptunnel.ru/api/v1/access/changeRole", { method: "POST", headers: { Authorization: key, "Content-Type": "application/json", }, body: JSON.stringify(body),})if (!response.ok) throw new Error(await response.text())console.log(await response.json())Example response
Section titled “Example response”{ "code": 0, "changed": 1, "failed": 1, "failedLogins": [ { "login": "petrov", "reason": "not_found", "message": "Employee not found in the organization." } ]}{ "code": 3, "message": "Invalid input, check schema issues.", "details": []}{ "error": { "message": "Unauthorized", "type": "unauthorized_request_error", "param": null, "code": null }}{ "code": 7, "message": "Not allowed to perform this action for the organization."}{ "code": 13, "message": "This section is not available from a personal account. Use a business organization API key."}{ "code": 1, "message": "Internal server error.", "trace_id": "66a346f64dcb57627c03d596"}