<!-- Generated by scripts/build-docs.js. Edit docs/swagger.yaml or docs/guides/, then run `npm run docs:build`. -->

# Create a team

`POST https://marketplace-api.sequifi.com/v1/teams`

Module: Teams · operationId: `createTeam` · Auth: `Authorization: Bearer <token>`
Web page: https://apidocs.sequifi.com/#/api/create-team

Creates one dated team with a Team Manager and members, as on the Teams page in Sequifi. There is no API to change or delete a team: later roster changes are made on the Teams page, or by creating the next period's team. A rep can be on only one team at a time, so an overlapping membership is refused until you say how to resolve it.

**Before you call:**

- Confirm the manager and every member exist and are active with `GET /v1/users/{id}`. An unknown user id most likely comes back as an unreadable `502`, not a `422`.
- To check for conflicts first, call `GET /v1/teams?team_member_id=<id>&effective_date=<start_date>` for each member.
- Always send `end_date`. An open-ended membership overlaps every later period, so the next team for that rep will conflict.

**What happens:**

The call waits for the result (up to 25 seconds) and checks, in this order:

- A team with the same `team_name`, `start_date` and `team_manager_id` already exists: `409 TEAM_ALREADY_EXISTS` with `data.team_id`.
- The manager or a member is dismissed, terminated or contract-ended: `422 MANAGER_NOT_ACTIVE` or `422 MEMBER_NOT_ACTIVE`.
- A member is on another team during these dates: `409 MEMBER_CONFLICT`. `data.conflicts` lists every conflict at once. Resend the same body with one `member_conflict_resolutions` entry for each listed member: `move_new_start` ends the old membership the day before this team starts; `custom` moves the member on `custom_date` (inside this team's dates) and ends the old membership the day before; `remove` deletes the old membership as if it never existed. Resolutions change the other team's memberships and overrides, so choose deliberately.

If every check passes:

- The team (type `lead`) and its memberships are created. A manager listed in `team_members` is left out of the members. Each member's current team in Sequifi is set to this team.
- With `manager_gets_override: true`, the Team Manager becomes each member's manager for the team's dates, which affects override pay. For a member who already reports to someone else, `manager_override_resolutions` says `keep` (leave their manager) or `reassign` (move them to the Team Manager).
- No emails are sent. Changes are recorded as made by the Marketplace API.

**Idempotency and retries:**

- Safe to retry with the identical body. You get `201` (the first attempt did not land), `409 TEAM_ALREADY_EXISTS` with `data.team_id` (it did), or `409 CREATE_IN_PROGRESS` (another create is still running: wait 1 to 2 seconds and retry).
- Changing `team_name`, `start_date` or `team_manager_id` on a retry creates a second team.
- Creates run one at a time per company. Send a period's teams in sequence, not in parallel.
- A `504` is ambiguous: re-post the identical body and read the result.

**Formats:**

- Dates are `YYYY-MM-DD`. `end_date` must be on or after `start_date`; send null or leave it out for open-ended.
- `manager_gets_override` must be a JSON boolean (`true` or `false`), not `0`, `1` or a string.
- `team_members`: up to 200 user ids, no repeats. Numeric strings are accepted.
- Other fields (for example `type`, `office_id`, `location_id` or manual overrides) are ignored without an error.
- The `201` response has `message: "Successfully."` and the team as stored. Membership dates can differ from the request after a `custom` resolution.

**Errors:**

- `400`: the body failed a check before it was sent. The message names the field, for example `team_name is required`, `start_date is required and must be a YYYY-MM-DD date`, `end_date must be on or after start_date`, `manager_gets_override must be true or false`, `team_members must not repeat the same user` (with `data.duplicates`) or `a custom resolution requires custom_date as a YYYY-MM-DD date`.
- `409`: `MEMBER_CONFLICT`, `TEAM_ALREADY_EXISTS` or `CREATE_IN_PROGRESS` in `data.code`.
- `422`: `MANAGER_NOT_ACTIVE` (with `data.team_manager_id`) or `MEMBER_NOT_ACTIVE` (with `data.member_ids`).
- `500 The team could not be created.` (`data.code` `CREATE_FAILED`) or `500 Could not resolve the tenant host`. Contact Sequifi support if it repeats.
- `502 Could not reach the tenant` or `502 The tenant returned an unreadable response`. The second most likely also covers unknown user ids, a `custom_date` outside the team's dates, going over about 60 creates a minute for your company, and unexpected errors. No `Retry-After` header is sent. Check the ids, wait, then retry the identical body.
- `503`: the company is not set up for team creation over the API (`data.code` `NOT_PROVISIONED` in one case). Contact Sequifi support.
- `504`: the team may still have been created. Re-post the identical body.

**Common mistakes:**

- Using `team_id` on `POST /v1/onboarding` to put someone on a team. Only this endpoint writes team memberships.
- Reading the id in the `TEAM_ALREADY_EXISTS` message as the manager's id. It is the existing team's id; use `data.team_id`.

**Related:**

- `GET /v1/teams/{id}` reads the team back.
- `GET /v1/teams?team_member_id=<user_id>&effective_date=<date>` shows which team a rep is on.

## Request body

- `team_name` (string, **required**): Team name. Leading and trailing spaces are trimmed. Part of the duplicate check, so keep it identical on retries. Max length: 255. Example: `Team Alpha - Sep 6`.
- `start_date` (string (date), **required**): First day of the team, `YYYY-MM-DD`. Part of the duplicate check. Example: `2026-09-06`.
- `end_date` (string (date), nullable): Last day of the team, on or after `start_date`. Always send one for a weekly roster. Example: `2026-09-12`.
- `team_manager_id` (integer, nullable): The Team Manager's user id. Must be an active user. Part of the duplicate check. Example: `72`.
- `team_members` (array of integer): Active user ids, at most 200, with no repeats. Max items: 200.
- `manager_gets_override` (boolean): The "Team Manager gets Override" setting. When true, the Team Manager becomes the manager of each member for the team's dates. Must be a JSON boolean. Default: `false`. Example: `false`.
- `member_conflict_resolutions` (array of object): Send on the retry after `409 MEMBER_CONFLICT`, one entry per member named in `data.conflicts`.
  - `member_id` (integer, **required**): The conflicting member's user id. Example: `428`.
  - `type` (string, **required**): `move_new_start` ends the old membership the day before this team starts. `custom` moves the member on `custom_date`. `remove` deletes the old membership. One of: `remove`, `move_new_start`, `custom`. Example: `move_new_start`.
  - `custom_date` (string (date), nullable): Required when `type` is `custom`. Must fall inside this team's dates. Example: `2026-09-08`.
- `manager_override_resolutions` (array of object): Only used with `manager_gets_override: true`. For a member who already reports to someone else: `keep` leaves their manager, `reassign` moves them to the Team Manager for the team's dates.
  - `member_id` (integer, **required**): The member's user id. Example: `487`.
  - `action` (string, **required**): What to do with the member's current manager. One of: `keep`, `reassign`. Example: `reassign`.

Example (weekly_team): A weekly team with three members

```json
{
  "team_name": "Team Alpha - Sep 6",
  "start_date": "2026-09-06",
  "end_date": "2026-09-12",
  "team_manager_id": 72,
  "team_members": [
    428,
    487,
    489
  ],
  "manager_gets_override": false
}
```

Example (retry_with_resolution): The same body resent after a MEMBER_CONFLICT

```json
{
  "team_name": "Team Alpha - Sep 6",
  "start_date": "2026-09-06",
  "end_date": "2026-09-12",
  "team_manager_id": 72,
  "team_members": [
    428,
    487,
    489
  ],
  "manager_gets_override": false,
  "member_conflict_resolutions": [
    {
      "member_id": 428,
      "type": "move_new_start"
    }
  ]
}
```

## Example request

```bash
curl -X POST "https://marketplace-api.sequifi.com/v1/teams" \
  -H "Authorization: Bearer $SEQUIFI_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"team_name":"Team Alpha - Sep 6","start_date":"2026-09-06","end_date":"2026-09-12","team_manager_id":72,"team_members":[428,487,489],"manager_gets_override":false}'
```

## Responses

### 201: Created. The team as stored, with each membership's dates.

- `status` (integer): Same as the HTTP status code. Example: `201`.
- `message` (string) Example: `Successfully.`.
- `data` (object)
  - `id` (integer): New team id. Use it with `GET /v1/teams/{id}`.
  - `team_name` (string): Team name as stored.
  - `type` (string): Always `lead`.
  - `start_date` (string): First day, `YYYY-MM-DD`.
  - `end_date` (string, nullable): Last day, `YYYY-MM-DD`, or null.
  - `manager_gets_override` (boolean): The "Team Manager gets Override" setting.
  - `team_manager_id` (integer, nullable): The Team Manager's user id.
  - `team_members` (array of object): Memberships as stored.
    - `id` (integer): Member's user id.
    - `start_date` (string): First day on the team, `YYYY-MM-DD`.
    - `end_date` (string, nullable): Last day on the team, `YYYY-MM-DD`, or null.

```json
{
  "status": 201,
  "message": "Successfully.",
  "data": {
    "id": 44,
    "team_name": "Team Alpha - Sep 6",
    "type": "lead",
    "start_date": "2026-09-06",
    "end_date": "2026-09-12",
    "manager_gets_override": false,
    "team_manager_id": 72,
    "team_members": [
      {
        "id": 428,
        "start_date": "2026-09-06",
        "end_date": "2026-09-12"
      },
      {
        "id": 487,
        "start_date": "2026-09-06",
        "end_date": "2026-09-12"
      },
      {
        "id": 489,
        "start_date": "2026-09-06",
        "end_date": "2026-09-12"
      }
    ]
  }
}
```

### 400: The body failed a check before it was sent. The message names the field.

Example (missing_start_date): start_date missing or not a real date

```json
{
  "status": 400,
  "message": "start_date is required and must be a YYYY-MM-DD date",
  "data": {}
}
```

### 401: Missing, unknown, expired or disabled token. Sent by the gateway as `{"message":"Unauthorized"}`, without `status` or `data`.

```json
{
  "message": "Unauthorized"
}
```

### 409: A member is already on another team for these dates, this team already exists, or another create is running. Branch on `data.code`.

Example (member_conflict): One or more members are already on another team

```json
{
  "status": 409,
  "message": "One or more team_members already belong to another team during this period. Resend with a member_conflict_resolutions entry for each member listed in data.conflicts.",
  "data": {
    "code": "MEMBER_CONFLICT",
    "conflicts": [
      {
        "member_id": 428,
        "team_id": 42,
        "team_name": "Team Bravo - Sep 6",
        "membership_start_date": "2026-09-06",
        "membership_end_date": "2026-09-12"
      },
      {
        "member_id": 487,
        "team_id": 42,
        "team_name": "Team Bravo - Sep 6",
        "membership_start_date": "2026-09-06",
        "membership_end_date": "2026-09-12"
      }
    ]
  }
}
```

### 422: The Team Manager or a member is not an active user. Unknown user ids most likely return `502` instead.

Example (member_not_active): One or more members is not an active user

```json
{
  "status": 422,
  "message": "These team_members are not active users and cannot be added to a team: 530, 541.",
  "data": {
    "code": "MEMBER_NOT_ACTIVE",
    "member_ids": [
      530,
      541
    ]
  }
}
```

### 500: The team could not be created, or the company's Sequifi address could not be resolved.

```json
{
  "status": 500,
  "message": "The team could not be created.",
  "data": {
    "code": "CREATE_FAILED"
  }
}
```

### 502: Your company's Sequifi app could not be reached, or sent a response the API could not read. The second case most likely also covers unknown user ids, an unusable `custom_date` and rate limits. Check the ids, wait, and retry the identical body.

Example (unreadable): Unreadable response (likely a validation or rate-limit error)

```json
{
  "status": 502,
  "message": "The tenant returned an unreadable response",
  "data": {}
}
```

### 503: Your company is not set up for team creation over the API. Contact Sequifi support.

Example (not_configured): Not configured

```json
{
  "status": 503,
  "message": "This tenant is not configured for team creation over the API. Contact Sequifi support.",
  "data": {}
}
```

### 504: No answer in time. The team may still have been created. Re-post the identical body.

```json
{
  "status": 504,
  "message": "The tenant did not respond in time. The team may still have been created — re-post the identical body: you will get 201 if it was not, or 409 TEAM_ALREADY_EXISTS with the existing team id if it was. Do not change team_name or start_date on a retry.",
  "data": {}
}
```
