# Roles

List and change your teams. The Harvest API calls a team a role. A role here is a team. A team gives its people access to the team's projects.

HTML version: https://t.momentic.studio/docs/api/roles

## Endpoints

- `GET /api/v2/roles`: [List roles](https://t.momentic.studio/docs/api/roles#get-roles)
- `GET /api/v2/roles/{role_id}`: [Retrieve a role](https://t.momentic.studio/docs/api/roles#get-roles-role-id)
- `POST /api/v2/roles`: [Create a role](https://t.momentic.studio/docs/api/roles#post-roles)
- `PATCH /api/v2/roles/{role_id}`: [Update a role](https://t.momentic.studio/docs/api/roles#patch-roles-role-id)
- `DELETE /api/v2/roles/{role_id}`: [Delete a role](https://t.momentic.studio/docs/api/roles#delete-roles-role-id)

## List roles

`GET /api/v2/roles`

Supported with differences. Scope: `reports:read`.

Roles are the app's teams. A member is refused (403).

Query parameters:

| Name            | Type     | Required | Description                                                                                                    |
| --------------- | -------- | -------- | -------------------------------------------------------------------------------------------------------------- |
| `updated_since` | datetime | no       | Only records changed at or after this ISO 8601 date-time. A value that is not a date-time is refused with 400. |
| `page`          | integer  | no       | The page to return, from 1. Default 1. A page past the end returns no records.                                 |
| `per_page`      | integer  | no       | Records per page, 1 to 2000. Default 2000. Another value is refused with 400.                                  |

Returns 200 with a page of role objects under `roles`.

Example request:

```bash
curl "https://t.momentic.studio/api/v2/roles" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Harvest-Account-Id: $ACCOUNT_ID" \
  -H "User-Agent: MyApp (admin@example.com)"
```

Example response, status 200:

```json
{
  "roles": [
    {
      "id": 7001,
      "name": "Design",
      "user_ids": [
        1001
      ],
      "created_at": "2026-01-05T15:00:00Z",
      "updated_at": "2026-01-05T15:00:00Z"
    }
  ],
  "per_page": 2000,
  "total_pages": 1,
  "total_entries": 1,
  "next_page": null,
  "previous_page": null,
  "page": 1,
  "links": {
    "first": "https://t.momentic.studio/api/v2/roles?page=1&per_page=2000&ref=first",
    "next": null,
    "previous": null,
    "last": "https://t.momentic.studio/api/v2/roles?page=1&per_page=2000&ref=last"
  }
}
```

## Retrieve a role

`GET /api/v2/roles/{role_id}`

Supported with differences. Scope: `reports:read`.

Returns 200 with a role object.

Example request:

```bash
curl "https://t.momentic.studio/api/v2/roles/7001" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Harvest-Account-Id: $ACCOUNT_ID" \
  -H "User-Agent: MyApp (admin@example.com)"
```

Example response, status 200:

```json
{
  "id": 7001,
  "name": "Design",
  "user_ids": [
    1001
  ],
  "created_at": "2026-01-05T15:00:00Z",
  "updated_at": "2026-01-05T15:00:00Z"
}
```

## Create a role

`POST /api/v2/roles`

Supported with differences. Scope: `people:write`.

Creates a team. A team gives its people access to the team's projects.

Body, as JSON or form fields:

| Name       | Type      | Required | Description                           |
| ---------- | --------- | -------- | ------------------------------------- |
| `name`     | string    | yes      | The team's name, up to 60 characters. |
| `user_ids` | integer[] | no       | Its people.                           |

Returns 201 with a role object.

Example request:

```bash
curl -X POST "https://t.momentic.studio/api/v2/roles" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Harvest-Account-Id: $ACCOUNT_ID" \
  -H "User-Agent: MyApp (admin@example.com)" \
  -H "Content-Type: application/json" \
  -d '{"name":"Example Client"}'
```

Example response, status 201:

```json
{
  "id": 7001,
  "name": "Design",
  "user_ids": [
    1001
  ],
  "created_at": "2026-01-05T15:00:00Z",
  "updated_at": "2026-01-05T15:00:00Z"
}
```

## Update a role

`PATCH /api/v2/roles/{role_id}`

Supported with differences. Scope: `people:write`.

Body, as JSON or form fields:

| Name       | Type      | Required | Description                    |
| ---------- | --------- | -------- | ------------------------------ |
| `name`     | string    | no       | The team's name.               |
| `user_ids` | integer[] | no       | Its people; replaces the list. |

Returns 200 with a role object.

Example request:

```bash
curl -X PATCH "https://t.momentic.studio/api/v2/roles/7001" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Harvest-Account-Id: $ACCOUNT_ID" \
  -H "User-Agent: MyApp (admin@example.com)"
```

Example response, status 200:

```json
{
  "id": 7001,
  "name": "Design",
  "user_ids": [
    1001
  ],
  "created_at": "2026-01-05T15:00:00Z",
  "updated_at": "2026-01-05T15:00:00Z"
}
```

## Delete a role

`DELETE /api/v2/roles/{role_id}`

Supported with differences. Scope: `people:write`.

Archives the team, which removes the access it gave. The team's history stays.

Returns 200 with no body.

Example request:

```bash
curl -X DELETE "https://t.momentic.studio/api/v2/roles/7001" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Harvest-Account-Id: $ACCOUNT_ID" \
  -H "User-Agent: MyApp (admin@example.com)"
```

## The role object

| Field        | Type      | Description                       |
| ------------ | --------- | --------------------------------- |
| `id`         | integer   | The role's id.                    |
| `name`       | string    | The team's name.                  |
| `user_ids`   | integer[] | The ids of the team's people.     |
| `created_at` | datetime  | When the record was created.      |
| `updated_at` | datetime  | When the record was last changed. |
