# Update a media recipe

> Changes only the fields you send. Only the recipe's creator can change it.

Source: https://docs.xplantpro.com/docs/api/media/update-media-recipe

`PATCH https://app.xplantpro.com/api/v1/media-recipes/{id}`

- Required scope: `write:media_recipes`
- Credentials: workspace API key (`xpk_`)
- Idempotency-Key: ignored on this endpoint

A change to the formulation — the title, notes, components, pH or preparation notes — records a new version and raises `version`. Earlier versions are kept, and records already linked to the recipe keep the version they were linked to. Changing `status`, `visibility` or `is_public` does not create a version.

`components` replaces the whole list, so send every component to keep, with its `id`.

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string (uuid) | Yes | The record's id. |

## Request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | No | The recipe's name. 1–200 characters. |
| `components` | object[] | No | The complete ingredient list. It replaces the current one, so send every component to keep, with its `id`. Up to 100 items. |
| `components[].id` | string | No | Your id for this component. Kept as given; when left out, one is assigned and returned, so an update can send it back. 1–64 characters. |
| `components[].name` | string | Yes | The ingredient, for example `Sucrose` or `6-BAP`. 1–200 characters. |
| `components[].qty` | string | Yes | The amount as the recipe writes it, for example `30` or `0.5`. 1–50 characters. |
| `components[].unit` | string | No | The unit of `qty`, for example `g/L` or `mg/L`. 1–20 characters. |
| `components[].concentration` | string | No | A concentration, when the recipe states one apart from the amount. 1–50 characters. |
| `notes` | string \| null | No | Free-text notes, up to 500 characters. `null` clears them. Up to 500 characters. |
| `status` | `"active"` \| `"archived"` \| `"deprecated"` \| `"draft"` \| `"published"` | No | One of `active`, `archived`, `deprecated`, `draft`, `published`. |
| `visibility` | `"private"` \| `"team"` | No | Who in the workspace can see the recipe. `private`: only the key's owner, who is recorded as its creator. `team`: everyone in the workspace. |
| `is_public` | boolean | No | Publish the recipe to xPlant's public recipe library, where anyone can read it. A `draft` recipe stays out of the library either way. |
| `ph_target` | number \| null | No | Target pH, 0 to 14. Stored to two decimal places. `null` clears it. From 0 to 14. |
| `sterilization_notes` | string \| null | No | How to sterilize the medium, up to 500 characters. Up to 500 characters. |
| `storage_notes` | string \| null | No | How to store the prepared medium, up to 500 characters. Up to 500 characters. |
| `usage_notes` | string \| null | No | How to use the medium, up to 500 characters. Up to 500 characters. |

## Example

**curl**

```bash
curl -X PATCH https://app.xplantpro.com/api/v1/media-recipes/4b6d8f0a-2c4e-4d6f-8a0c-2e4b6d8f0a2c \
  -H "Authorization: Bearer $XPLANT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "MS + 0.5 mg/L BAP",
    "components": [
      {
        "id": "c1a2b3c4-d5e6-4f70-8a9b-0c1d2e3f4a5b",
        "name": "MS basal salts",
        "qty": "4.4",
        "unit": "g/L"
      },
      {
        "id": "d2b3c4d5-e6f7-4a81-9b0c-1d2e3f4a5b6c",
        "name": "Sucrose",
        "qty": "30",
        "unit": "g/L"
      },
      {
        "id": "e3c4d5e6-f7a8-4b92-8c1d-2e3f4a5b6c7d",
        "name": "6-BAP",
        "qty": "0.5",
        "unit": "mg/L"
      },
      {
        "id": "f4d5e6f7-a8b9-4ca3-9d2e-3f4a5b6c7d8e",
        "name": "Agar",
        "qty": "7",
        "unit": "g/L"
      }
    ]
  }'
```

**JavaScript**

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

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

const recipe = await client.mediaRecipes.update(
  "4b6d8f0a-2c4e-4d6f-8a0c-2e4b6d8f0a2c",
  {
    title: "MS + 0.5 mg/L BAP",
    components: [
      {
        id: "c1a2b3c4-d5e6-4f70-8a9b-0c1d2e3f4a5b",
        name: "MS basal salts",
        qty: "4.4",
        unit: "g/L",
      },
      {
        id: "d2b3c4d5-e6f7-4a81-9b0c-1d2e3f4a5b6c",
        name: "Sucrose",
        qty: "30",
        unit: "g/L",
      },
      {
        id: "e3c4d5e6-f7a8-4b92-8c1d-2e3f4a5b6c7d",
        name: "6-BAP",
        qty: "0.5",
        unit: "mg/L",
      },
      {
        id: "f4d5e6f7-a8b9-4ca3-9d2e-3f4a5b6c7d8e",
        name: "Agar",
        qty: "7",
        unit: "g/L",
      },
    ],
  },
);
```

**Python**

```python
import os
import requests

resp = requests.patch(
    "https://app.xplantpro.com/api/v1/media-recipes/4b6d8f0a-2c4e-4d6f-8a0c-2e4b6d8f0a2c",
    headers={"Authorization": f"Bearer {os.environ['XPLANT_API_KEY']}"},
    json={
        "title": "MS + 0.5 mg/L BAP",
        "components": [
            {
                "id": "c1a2b3c4-d5e6-4f70-8a9b-0c1d2e3f4a5b",
                "name": "MS basal salts",
                "qty": "4.4",
                "unit": "g/L",
            },
            {
                "id": "d2b3c4d5-e6f7-4a81-9b0c-1d2e3f4a5b6c",
                "name": "Sucrose",
                "qty": "30",
                "unit": "g/L",
            },
            {
                "id": "e3c4d5e6-f7a8-4b92-8c1d-2e3f4a5b6c7d",
                "name": "6-BAP",
                "qty": "0.5",
                "unit": "mg/L",
            },
            {
                "id": "f4d5e6f7-a8b9-4ca3-9d2e-3f4a5b6c7d8e",
                "name": "Agar",
                "qty": "7",
                "unit": "g/L",
            },
        ],
    },
    timeout=10,
)
body = resp.json()
if not body["ok"]:
    raise RuntimeError(f"{resp.status_code} {body['code']}: {body['error']}")
recipe = body["data"]
```

## Response

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

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string (uuid) | Yes | — |
| `title` | string | Yes | — |
| `status` | string \| null | Yes | One of `active`, `archived`, `deprecated`, `draft`, `published`. |
| `origin` | string \| null | Yes | Where the recipe came from, for example `user` or `imported`. |
| `visibility` | string | Yes | `private`: only its creator can see it. `team`: everyone in the workspace can. |
| `is_public` | boolean | Yes | Published to xPlant's public recipe library. |
| `notes` | string \| null | Yes | — |
| `ph_target` | number \| null | Yes | Target pH. |
| `sterilization_notes` | string \| null | Yes | — |
| `storage_notes` | string \| null | Yes | — |
| `usage_notes` | string \| null | Yes | — |
| `components` | object[] | Yes | The ingredients, in order. |
| `components[].id` | string | Yes | The component's id. Send it back in an update to keep the component. |
| `components[].name` | string | Yes | The ingredient. |
| `components[].qty` | string | Yes | The amount as the recipe writes it. |
| `components[].unit` | string \| null | Yes | The unit of `qty`. |
| `components[].concentration` | string \| null | Yes | A concentration, when the recipe states one apart from the amount. |
| `version` | integer | Yes | The recipe's version. It goes up by one each time the formulation changes, and every version is kept. |
| `created_by` | string | Yes | User id of the workspace member who created the recipe. Only they can change it. |
| `created_at` | string \| null | Yes | ISO 8601. |

```json title="Response"
{
  "ok": true,
  "data": {
    "id": "a3d5f7b9-1c2e-4f6a-8b0d-2e4f6a8c0e1f",
    "title": "MS + 0.5 mg/L BAP",
    "status": "active",
    "origin": "user",
    "visibility": "team",
    "is_public": false,
    "notes": "Shoot multiplication medium for aroid cultures.",
    "ph_target": 5.8,
    "sterilization_notes": "Autoclave for 20 minutes at 121 °C.",
    "storage_notes": "Keep poured vessels at 4 °C and use within two weeks.",
    "usage_notes": null,
    "components": [
      {
        "id": "c1a2b3c4-d5e6-4f70-8a9b-0c1d2e3f4a5b",
        "name": "MS basal salts",
        "qty": "4.4",
        "unit": "g/L",
        "concentration": null
      },
      {
        "id": "d2b3c4d5-e6f7-4a81-9b0c-1d2e3f4a5b6c",
        "name": "Sucrose",
        "qty": "30",
        "unit": "g/L",
        "concentration": null
      },
      {
        "id": "e3c4d5e6-f7a8-4b92-8c1d-2e3f4a5b6c7d",
        "name": "6-BAP",
        "qty": "0.5",
        "unit": "mg/L",
        "concentration": null
      },
      {
        "id": "f4d5e6f7-a8b9-4ca3-9d2e-3f4a5b6c7d8e",
        "name": "Agar",
        "qty": "7",
        "unit": "g/L",
        "concentration": null
      }
    ],
    "version": 2,
    "created_by": "0d7e4b9a-6f21-4c3e-8a5b-2e9f1c7d4a60",
    "created_at": "2026-09-25T14:12:03.000Z"
  }
}
```

| Response header | Meaning |
| --- | --- |
| `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. |
| `403` | `MEDIA_RECIPE_NOT_OWNER` | The key's owner can see the recipe but did not create it. Only a recipe's creator can change it. |
| `404` | `NOT_FOUND` | No recipe with this id is visible to the key's owner in the workspace: it does not exist there, or it is another member's private recipe. |
| `422` | `VALIDATION_ERROR` | A field failed validation. `error` names the first one, for example `title: title is required`. |
| `429` | `RATE_LIMIT_EXCEEDED` | Too many requests for this key, device token or workspace. Wait `Retry-After` seconds. |
| `500` | `MEDIA_RECIPE_UPDATE_FAILED` | The change could not be saved. Retry later. |

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