> This page is for In Vivo.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.invivo.benchling.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.invivo.benchling.com/_mcp/server.

# Assign study group treatments

POST https://acme-api.invivo.benchling.com/api/public/v1-beta/studies/{studyId}/groups/{studyGroupId}/treatments/assign
Content-Type: application/json

Assigns between 1 and 100 of the study's treatments to the study group. Only treatments classified as `treatment` can be assigned; pre-treatments and disease inductions cannot. A treatment the group already holds is left as it is and no treatment is unassigned, so the same request may be sent again without assigning anything twice. The request is validated as a whole; if any item is invalid, none are assigned. The study may not be archived or canceled.

Reference: https://docs.invivo.benchling.com/in-vivo/api/study-group-treatments/study-group-treatment-assign

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Path parameters

- `studyId` (string, required) — The unique identifier of the study.
- `studyGroupId` (string, required) — The unique identifier of the study group.

### Body (application/json)

This endpoint expects a TreatmentsAssignV1.

- `treatment_ids` (list of string, required) — Between 1 and 100 treatments on the study, each listed at most once. Only treatments classified as `treatment` can be assigned; a pre-treatment or disease induction is rejected.

## Response

### 204

The treatments were assigned.

## Errors

### 400 Bad Request Error

The request was rejected. Validation failures return a `ValidationErrorResponse`; an unrecognised `X-Studies-Api-Version` header returns an `AuthErrorResponse` with the code `invalid_header`.

- `BadRequestErrorResponse`
  - ValidationErrorResponse: ValidationErrorResponse
  - AuthErrorResponse: AuthErrorResponse
  - ProblemDetail: ProblemDetail

### 401 Unauthorized Error

Authentication failed. The body is normally empty; when an otherwise valid access token is missing required claims the body is an `AuthErrorResponse` with the code `invalid_token`.

- `any`

### 403 Forbidden Error

The access token does not grant the scopes this operation requires. The body is normally empty; when the token's team is missing or deleted the body is an `AuthErrorResponse` with the code `invalid_data`.

- `any`

### 429 Too Many Requests Error

A rate limit was exceeded. Retry once the window resets; no `Retry-After` header is sent, so use `X-RateLimit-Reset`.

- `error` (any, required) — A machine-readable error code.
- `message` (string, required) — A human-readable explanation of the failure.

## Types

### ValidationErrorResponse

Returned when a request body or parameter fails validation.

- `message` (string, required) — A summary of the failure.
- `errors` (map from string to list of string, required) — Failure messages keyed by the offending field, using the field's name as it appears on the wire. Nested fields are dotted, e.g. `schedule.duration`.

### AuthErrorResponse

Returned when a request is rejected during authentication, before it is processed.

- `error` (enum, required) — A machine-readable error code.
  - Allowed values: `invalid_header`, `invalid_token`, `invalid_data`
- `error_description` (string, required) — A human-readable explanation of the failure.

### ProblemDetail

An RFC 9457 problem detail, returned when a request is rejected before it reaches a controller method — most commonly an unparseable or absent JSON body. Unlike the rest of this API, null members are omitted rather than serialised as `null`.

- `title` (string, required) — A short, human-readable summary of the problem type.
- `status` (integer, required) — The HTTP status code, repeated in the body.
- `detail` (string, required) — A human-readable explanation specific to this occurrence.
- `instance` (string, required) — The path of the request that produced the problem.

## Examples

**Request**

```json
{
  "treatment_ids": [
    "tmt_3zQ9mKpNvR5xTw6YbCdFgR",
    "tmt_8aD4nLqWvS7yUx1ZbEfHjM"
  ]
}
```

**SDK Code**

```python
import requests

url = "https://acme-api.invivo.benchling.com/api/public/v1-beta/studies/sdy_3vQ8kZpLmN2xRt7YwBcDfG/groups/grp_9nT4kZpMvR2xQw8YbCdFgJ/treatments/assign"

payload = { "treatment_ids": ["tmt_3zQ9mKpNvR5xTw6YbCdFgR", "tmt_8aD4nLqWvS7yUx1ZbEfHjM"] }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://acme-api.invivo.benchling.com/api/public/v1-beta/studies/sdy_3vQ8kZpLmN2xRt7YwBcDfG/groups/grp_9nT4kZpMvR2xQw8YbCdFgJ/treatments/assign';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"treatment_ids":["tmt_3zQ9mKpNvR5xTw6YbCdFgR","tmt_8aD4nLqWvS7yUx1ZbEfHjM"]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```