# Create a task

> Adds a task to the workspace. Set priority, priority_rank and assigned_to in the same call so a scheduler can place work in one request. Order set this way counts as automatic, so a later hand-reorder in the app takes precedence over your next sync.

Source: https://docs.xplantpro.com/docs/api/tasks/create-task

`POST https://app.xplantpro.com/api/v1/tasks`

- Required scope: `write:tasks`
- Credentials: workspace API key (`xpk_`)
- Idempotency-Key: honoured (24 hours)

Link the task to the plant or explant it is about with `entity_type` and `entity_id` — send both or neither.

Send an `Idempotency-Key` header to make retries safe: a repeat with the same key within 24 hours returns the first response instead of writing twice. See [Idempotency](https://docs.xplantpro.com/docs/idempotency.md).

## Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | string | No | Any unique string you choose per logical write. A retry carrying the same key within 24 hours returns the first result instead of writing again. Scoped to your API key and this operation. 8–255 characters. Must match `^[A-Za-z0-9._:~-]+$`. |

## Request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | Yes | 1–300 characters. |
| `due_date` | string (date-time) | No | — |
| `is_all_day` | boolean | No | — |
| `category` | `"media_prep"` \| `"transfer"` \| `"contamination"` \| `"subculture"` \| `"sop_review"` \| `"acclimation"` \| `"cleaning"` \| `"monitoring"` \| `"other"` | No | Default `"media_prep"`. |
| `notes` | string | No | Up to 5000 characters. |
| `priority` | `"low"` \| `"medium"` \| `"high"` \| `"urgent"` | No | — |
| `priority_rank` | number \| null | No | — |
| `workflow_status` | `"backlog"` \| `"todo"` \| `"in_progress"` \| `"waiting_blocked"` \| `"review"` \| `"done"` | No | Default `"todo"`. |
| `assigned_to` | string (uuid) | No | — |
| `genus` | string | No | 1–100 characters. |
| `entity_type` | `"plant"` \| `"explant"` | No | — |
| `entity_id` | string (uuid) | No | — |

## Example

**curl**

```bash
curl -X POST https://app.xplantpro.com/api/v1/tasks \
  -H "Authorization: Bearer $XPLANT_API_KEY" \
  -H "Idempotency-Key: bench-3-subculture-line-0412" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Transfer the Alocasia line onto fresh medium",
    "due_date": "2026-10-02T09:00:00.000Z",
    "category": "transfer",
    "priority": "high",
    "priority_rank": 1.5,
    "assigned_to": "0d7e4b9a-6f21-4c3e-8a5b-2e9f1c7d4a60",
    "genus": "Alocasia"
  }'
```

**JavaScript**

```js
import { XPlantClient } from "@shmaplex/xplant-sdk";

const client = new XPlantClient({ apiKey: process.env.XPLANT_API_KEY });

const task = await client.tasks.create(
  {
    title: "Transfer the Alocasia line onto fresh medium",
    due_date: "2026-10-02T09:00:00.000Z",
    category: "transfer",
    priority: "high",
    priority_rank: 1.5,
    assigned_to: "0d7e4b9a-6f21-4c3e-8a5b-2e9f1c7d4a60",
    genus: "Alocasia",
  },
  { idempotencyKey: "bench-3-subculture-line-0412" },
);
```

**Python**

```python
import os
import requests

resp = requests.post(
    "https://app.xplantpro.com/api/v1/tasks",
    headers={
        "Authorization": f"Bearer {os.environ['XPLANT_API_KEY']}",
        "Idempotency-Key": "bench-3-subculture-line-0412",
    },
    json={
        "title": "Transfer the Alocasia line onto fresh medium",
        "due_date": "2026-10-02T09:00:00.000Z",
        "category": "transfer",
        "priority": "high",
        "priority_rank": 1.5,
        "assigned_to": "0d7e4b9a-6f21-4c3e-8a5b-2e9f1c7d4a60",
        "genus": "Alocasia",
    },
    timeout=10,
)
body = resp.json()
if not body["ok"]:
    raise RuntimeError(f"{resp.status_code} {body['code']}: {body['error']}")
task = body["data"]
```

## Response

`201` with `{ "ok": true, "data": … }`. `data` holds the result.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string (uuid) | Yes | — |
| `title` | string | Yes | — |
| `status` | string | Yes | Board column: `backlog`, `todo`, `in_progress`, `waiting_blocked`, `review`, `done`. |
| `due_date` | string \| null | Yes | ISO 8601 timestamp. |
| `assigned_to` | string \| null | Yes | User id of the workspace member the task is assigned to. |
| `priority` | string \| null | Yes | — |
| `priority_rank` | number \| null | Yes | Queue position. Lower sorts first; null means the priority label decides. |
| `priority_source` | string | Yes | Where the current order came from: `default`, `auto`, `manual`. `manual` means a person placed the task, and automated writes leave it where it is unless they send `release: true`. |
| `category` | string \| null | Yes | — |
| `created_at` | string \| null | Yes | — |
| `entity_link` | object \| null | No | The plant or explant the task is about. Returned when you create, fetch or update one task; lists leave it out. |
| `entity_link.entity_type` | `"plant"` \| `"explant"` | Yes | — |
| `entity_link.entity_id` | string (uuid) | Yes | — |

```json title="Response"
{
  "ok": true,
  "data": {
    "id": "5b0f6f3e-2c1a-4d8e-9f47-0a6c3e1b7d22",
    "title": "Transfer the Alocasia line onto fresh medium",
    "status": "todo",
    "due_date": "2026-10-02T09:00:00.000Z",
    "assigned_to": "0d7e4b9a-6f21-4c3e-8a5b-2e9f1c7d4a60",
    "priority": "high",
    "priority_rank": 1.5,
    "priority_source": "auto",
    "category": "transfer",
    "created_at": "2026-09-25T14:12:03.000Z"
  }
}
```

| Response header | Meaning |
| --- | --- |
| `Idempotent-Replay` | `true` when this response is a replay of an earlier request with the same `Idempotency-Key`. |
| `X-Request-Id` | Identifies this request. Include it when you contact support. |

## Errors

| Status | Code | When |
| --- | --- | --- |
| `400` | `VALIDATION_ERROR` | The request body is not valid JSON. |
| `401` | `UNAUTHORIZED` | The key is missing, malformed or revoked, or its owner is no longer a member of the workspace. |
| `402` | `PAID_PLAN_REQUIRED` | The workspace's plan does not include the API. The full API is included with xPlant+ Teams and Enterprise; on Hobby and Pro Lab, keys can connect devices only. |
| `403` | `FORBIDDEN` | The key lacks a scope this operation requires, or its owner's current role in the workspace cannot use it — a key never does more than its owner can in xPlant. `error` names the scope, and for a role, the role it needs. |
| `403` | `DEVICE_TOKEN_NOT_ACCEPTED` | A device token was sent; this operation needs a workspace API key. |
| `409` | `IDEMPOTENCY_IN_FLIGHT` | A request with this `Idempotency-Key` is still being processed; retry after `Retry-After` seconds. |
| `422` | `VALIDATION_ERROR` | The `Idempotency-Key` header is malformed. |
| `422` | `VALIDATION_ERROR` | A field failed validation. `error` names the first one, for example `title: title is required`. |
| `422` | `VALIDATION_ERROR` | `assigned_to` is not an active member of the workspace, or the linked plant or explant is not in it. |
| `429` | `RATE_LIMIT_EXCEEDED` | Too many requests for this key, device token or workspace. Wait `Retry-After` seconds. |
| `500` | `TASK_CREATE_FAILED` | The task could not be saved. Retry with the same `Idempotency-Key`. |

Branch on `code`, never on the `error` text. See [Errors](https://docs.xplantpro.com/docs/errors.md).
