# Give a team a role on a repository

> Give a team a role on a repository in its workspace, or change it: read, triage, write, maintain or admin.

<div class="g1t-endpoint"><span class="g1t-method" data-method="put">PUT</span><code>/workspaces/{workspace}/teams/{team}/repos/{repo}</code></div>

Everyone in the team and in its child teams gets the role. Needs the Admin role on the repository. People only. Returns the repository as [`list_team_repos`](/reference/api/teams/list-team-repos/) lists it.

`repo` in the path is the repository's name in the team's workspace; a team has roles only on its own workspace's repositories. `role` is `read`, `triage`, `write`, `maintain` or `admin`. Everyone in the team and its child teams gets it; someone with a higher role otherwise keeps that. Needs the Admin role on the repository (`403` otherwise), and the `access:admin` scope. See [Access and roles](/guides/access-and-roles/).

- **Authentication:** Required. Send an [access token](/reference/api/#authentication) as `Authorization: Bearer`.
- **MCP tool:** [`team`](/reference/mcp/#team) with `action` `set_repo`, and the same inputs
- **Scope:** An access token needs [`access:admin`](/guides/authentication/#scopes).

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `workspace` | string | Yes | The workspace's slug, e.g. "flagon-io". |
| `team` | string | Yes | The team's slug, as in its mention @workspace/slug, e.g. "backend". |
| `repo` | string | Yes | The repository, in the team's workspace: its name, or "owner/name". |

## Body parameters

Send a JSON object. Names are `snake_case`, as in responses; the `camelCase` spelling is accepted too.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `role` | string | Yes | read: read and comment. triage: also label, assign and close. write: also push, merge and put agents to work. maintain: also settings and branch protection. admin: everything, including who has access. One of `read`, `triage`, `write`, `maintain`, `admin`. |

## Example request

```sh
curl -X PUT https://api.g1t.sh/workspaces/flagon-io/teams/backend/repos/hello \
  -H "Authorization: Bearer $G1T_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "role": "maintain"
  }'
```

## Example response

A successful request answers `200` with:

```json
{
  "repo": "flagon-io/hello",
  "repo_id": "rep_01m3m5q6p0e2qaw6mmjahk0qrr",
  "role": "maintain",
  "inherited_from": null
}
```

## Errors

A failed request answers with one of these statuses and a body like `{"error": {"code": "not_found", "message": "Repository not found."}}`. See [errors](/reference/api/#errors).

| Status | Code | When |
| --- | --- | --- |
| 401 | `unauthenticated` | A token is required, or the one sent is not valid. |
| 403 | `forbidden` | The token is valid but not allowed to do this, such as a member-only change or an agent token outside its repository. |
| 404 | `not_found` | It does not exist, or you cannot see it. |
| 409 | `conflict` | The request conflicts with the current state. |
| 422 | `invalid` | The input is not valid. `message` says which field and why. |
