> This page is for Developer Documentation.

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

# Create or update a registered AA sequence.

PATCH https://{tenant_name}.benchling.com/api/v2/aa-sequences/{entity_registry_id}:upsert
Content-Type: application/json

Create or update a registered AA sequence.

Schema field links can be populated using entity registry IDs or API IDs. In the `value` field of the [Field](#/components/schemas/FieldWithResolution) resource, the object `{"entityRegistryId": ENTITY_REGISTRY_ID}` may be provided instead of the API ID if desired (see example value).

Reference: https://docs.benchling.com/docs/api/v2/benchling-api/aa-sequences/upsert-aa-sequence

## Authentication

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

## Request

### Path parameters

- `entity_registry_id` (string, required)

### Body (application/json)

This endpoint expects an AaSequenceUpsert.

- `name` (string, required) — Name of the AA sequence.
- `registryId` (string, required)
- `schemaId` (string, required) — ID of the AA sequence's schema.
- `entityRegistryId` (string, required) — Registry ID of the entity in Benchling.
- `aminoAcids` (string, required) — Amino acids for the AA sequence.
- `annotations` (list of AaAnnotation, required) — Annotations to create on the AA sequence.
- `archiveRecord` (ArchiveRecordSet, optional) — Currently, we only support setting a null value for archiveRecord, which unarchives the item
- `fields` (map from string to FieldWithResolution, optional) — Fields to set on the AA sequence. Must correspond with the schema's field definitions. Every field should have its name as a key, mapping to an object with information about the value of the field.
- `aliases` (list of string, optional) — Aliases to add to the AA sequence
- `authorIds` (list of string, optional) — IDs of users to set as the AA sequence's authors.
- `customFields` (map from string to CustomField, optional) — Custom fields to add to the AA sequence. Every field should have its name as a key, mapping to an object with information about the value of the field.
- `folderId` (string, optional) — ID of the folder containing the AA sequence.

## Response

### 200

OK

- `aliases` (list of string, optional) — Array of aliases
- `aminoAcids` (string, optional) — Amino acids of the AA sequence.
- `annotations` (list of AaAnnotation, optional) — Array of annotation objects on the AA sequence.
- `apiURL` (string, optional) — The canonical url of the AA Sequence in the API.
- `archiveRecord` (ArchiveRecord, optional, nullable)
- `authors` (list of UserSummary, optional)
- `createdAt` (datetime, optional) — DateTime the AA sequence was created.
- `creator` (UserSummary, optional)
- `customFields` (map from string to CustomField, optional) — Custom fields set on the AA sequence.
- `entityRegistryId` (string, optional, nullable) — Registry ID of the AA sequence if registered.
- `fields` (map from string to Field, optional)
- `folderId` (string, optional, nullable) — ID of the folder that contains the AA sequence.
- `id` (string, optional) — ID of the AA sequence.
- `length` (integer, optional) — Number of amino acids in the AA sequence.
- `modifiedAt` (datetime, optional) — DateTime the AA sequence was last modified.
- `name` (string, optional) — Name of the AA sequence.
- `registrationOrigin` (RegistrationOrigin, optional, nullable)
- `registryId` (string, optional, nullable) — Registry the AA sequence is registered in.
- `schema` (SchemaSummary, optional, nullable)
- `url` (string, optional) — The path of the web URL, omitting the tenant domain
- `webURL` (string, optional) — URL of the AA sequence.

### 201

OK

- `aliases` (list of string, optional) — Array of aliases
- `aminoAcids` (string, optional) — Amino acids of the AA sequence.
- `annotations` (list of AaAnnotation, optional) — Array of annotation objects on the AA sequence.
- `apiURL` (string, optional) — The canonical url of the AA Sequence in the API.
- `archiveRecord` (ArchiveRecord, optional, nullable)
- `authors` (list of UserSummary, optional)
- `createdAt` (datetime, optional) — DateTime the AA sequence was created.
- `creator` (UserSummary, optional)
- `customFields` (map from string to CustomField, optional) — Custom fields set on the AA sequence.
- `entityRegistryId` (string, optional, nullable) — Registry ID of the AA sequence if registered.
- `fields` (map from string to Field, optional)
- `folderId` (string, optional, nullable) — ID of the folder that contains the AA sequence.
- `id` (string, optional) — ID of the AA sequence.
- `length` (integer, optional) — Number of amino acids in the AA sequence.
- `modifiedAt` (datetime, optional) — DateTime the AA sequence was last modified.
- `name` (string, optional) — Name of the AA sequence.
- `registrationOrigin` (RegistrationOrigin, optional, nullable)
- `registryId` (string, optional, nullable) — Registry the AA sequence is registered in.
- `schema` (SchemaSummary, optional, nullable)
- `url` (string, optional) — The path of the web URL, omitting the tenant domain
- `webURL` (string, optional) — URL of the AA sequence.

## Errors

### 400 Bad Request Error

Bad Request

- `error` (BadRequestErrorError, optional)

## Types

### AaAnnotation

- `color` (string, optional)
- `end` (integer, optional) — 0-based exclusive end index. The end of the AA sequence is always represented as 0.
- `id` (string, optional)
- `name` (string, optional)
- `notes` (string, optional)
- `start` (integer, optional) — 0-based inclusive start index.
- `type` (string, optional)

### ArchiveRecordSet

Currently, we only support setting a null value for archiveRecord, which unarchives the item

### FieldWithResolution

- `value` (FieldWithResolutionValue, required, nullable) — For single link fields, use the id of the item you want to link (eg. "seq_jdf8BV24"). For multi-link fields, use an array of ids of the items you want to link (eg. ["seq_jdf8BV24"])
- `displayValue` (string, optional, nullable)
- `isMulti` (boolean, optional)
- `textValue` (string, optional, nullable)
- `type` (enum, optional)
  - Allowed values: `dna_sequence_link`, `aa_sequence_link`, `custom_entity_link`, `entity_link`, `mixture_link`, `molecule_link`, `dropdown`, `part_link`, `translation_link`, `aa_part_link`, `base_molecule_link`, `blob_link`, `text`, `long_text`, `batch_link`, `storage_link`, `entry_link`, `assay_request_link`, `assay_result_link`, `assay_run_link`, `boolean`, `float`, `integer`, `datetime`, `date`, `json`

### CustomField

- `value` (string, optional)

### ArchiveRecord

- `reason` (string, optional)

### UserSummary

- `handle` (string, optional)
- `id` (string, optional)
- `name` (string, optional)

### Field

- `value` (FieldValue, required, nullable) — For single link fields, use the id of the item you want to link (eg. "seq_jdf8BV24"). For multi-link fields, use an array of ids of the items you want to link (eg. ["seq_jdf8BV24"])
- `displayValue` (string, optional, nullable)
- `isMulti` (boolean, optional)
- `textValue` (string, optional, nullable)
- `type` (enum, optional)
  - Allowed values: `dna_sequence_link`, `aa_sequence_link`, `custom_entity_link`, `entity_link`, `mixture_link`, `molecule_link`, `dropdown`, `part_link`, `translation_link`, `aa_part_link`, `base_molecule_link`, `blob_link`, `text`, `long_text`, `batch_link`, `storage_link`, `entry_link`, `assay_request_link`, `assay_result_link`, `assay_run_link`, `boolean`, `float`, `integer`, `datetime`, `date`, `json`

### RegistrationOrigin

- `originEntryId` (string, optional, nullable)
- `registeredAt` (datetime, optional)

### SchemaSummary

- `id` (string, optional)
- `name` (string, optional)

### BadRequestErrorError

- `message` (string, optional)
- `type` (enum, optional)
  - Allowed values: `invalid_request_error`
- `userMessage` (string, optional)

### FieldWithResolutionValue

For single link fields, use the id of the item you want to link (eg. "seq_jdf8BV24"). For multi-link fields, use an array of ids of the items you want to link (eg. ["seq_jdf8BV24"])

### FieldValue

For single link fields, use the id of the item you want to link (eg. "seq_jdf8BV24"). For multi-link fields, use an array of ids of the items you want to link (eg. ["seq_jdf8BV24"])

## Examples

### Example 1

**Request**

```json
{
  "name": "string",
  "registryId": "string",
  "schemaId": "string",
  "entityRegistryId": "string",
  "aminoAcids": "string",
  "annotations": [
    {}
  ]
}
```

**Response**

```json
{
  "aliases": [
    "string"
  ],
  "aminoAcids": "IKTATARRELAETSWTGDRLWGFSDNWAPALRRPSPSALGK",
  "annotations": [
    {
      "color": "string",
      "end": 1,
      "id": "prtnann_o7zMPG0P",
      "name": "string",
      "notes": "Cong et al Science. 2013 Jan 3.",
      "start": 1,
      "type": "Site"
    }
  ],
  "apiURL": "https://benchling.com/api/v2/aa-sequences/prtn_7nMBOMm0",
  "archiveRecord": {
    "reason": "Made in error"
  },
  "authors": [
    {
      "handle": "string",
      "id": "string",
      "name": "string"
    }
  ],
  "createdAt": "2024-01-15T09:30:00Z",
  "creator": {
    "handle": "string",
    "id": "string",
    "name": "string"
  },
  "customFields": {},
  "entityRegistryId": "string",
  "fields": {},
  "folderId": "string",
  "id": "prtn_ObbdtGhC",
  "length": 1,
  "modifiedAt": "2024-01-15T09:30:00Z",
  "name": "string",
  "registrationOrigin": {
    "originEntryId": "string",
    "registeredAt": "2024-01-15T09:30:00Z"
  },
  "registryId": "string",
  "schema": {
    "id": "string",
    "name": "string"
  },
  "url": "string",
  "webURL": "https://benchling.com/benchling/f/lib_55UxcIps-registry/prtn_7nMBOMm0-kedchain11/edit\""
}
```

**SDK Code**

```python
import requests

url = "https://{tenant_name}.benchling.com/api/v2/aa-sequences/entity_registry_id:upsert"

payload = {
    "name": "string",
    "registryId": "string",
    "schemaId": "string",
    "entityRegistryId": "string",
    "aminoAcids": "string",
    "annotations": [{}]
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://{tenant_name}.benchling.com/api/v2/aa-sequences/entity_registry_id:upsert';
const options = {
  method: 'PATCH',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"name":"string","registryId":"string","schemaId":"string","entityRegistryId":"string","aminoAcids":"string","annotations":[{}]}'
};

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

### Example 2

**Request**

```json
{
  "name": "string",
  "registryId": "string",
  "schemaId": "string",
  "entityRegistryId": "string",
  "aminoAcids": "string",
  "annotations": [
    {}
  ]
}
```

**Response**

```json
{
  "aliases": [
    "string"
  ],
  "aminoAcids": "IKTATARRELAETSWTGDRLWGFSDNWAPALRRPSPSALGK",
  "annotations": [
    {
      "color": "string",
      "end": 1,
      "id": "prtnann_o7zMPG0P",
      "name": "string",
      "notes": "Cong et al Science. 2013 Jan 3.",
      "start": 1,
      "type": "Site"
    }
  ],
  "apiURL": "https://benchling.com/api/v2/aa-sequences/prtn_7nMBOMm0",
  "archiveRecord": {
    "reason": "Made in error"
  },
  "authors": [
    {
      "handle": "string",
      "id": "string",
      "name": "string"
    }
  ],
  "createdAt": "2024-01-15T09:30:00Z",
  "creator": {
    "handle": "string",
    "id": "string",
    "name": "string"
  },
  "customFields": {},
  "entityRegistryId": "string",
  "fields": {},
  "folderId": "string",
  "id": "prtn_ObbdtGhC",
  "length": 1,
  "modifiedAt": "2024-01-15T09:30:00Z",
  "name": "string",
  "registrationOrigin": {
    "originEntryId": "string",
    "registeredAt": "2024-01-15T09:30:00Z"
  },
  "registryId": "string",
  "schema": {
    "id": "string",
    "name": "string"
  },
  "url": "string",
  "webURL": "https://benchling.com/benchling/f/lib_55UxcIps-registry/prtn_7nMBOMm0-kedchain11/edit\""
}
```

**SDK Code**

```python
import requests

url = "https://{tenant_name}.benchling.com/api/v2/aa-sequences/entity_registry_id:upsert"

payload = {
    "name": "string",
    "registryId": "string",
    "schemaId": "string",
    "entityRegistryId": "string",
    "aminoAcids": "string",
    "annotations": [{}]
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://{tenant_name}.benchling.com/api/v2/aa-sequences/entity_registry_id:upsert';
const options = {
  method: 'PATCH',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"name":"string","registryId":"string","schemaId":"string","entityRegistryId":"string","aminoAcids":"string","annotations":[{}]}'
};

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