# Standardizing Sample Naming via the API

A lab may receive samples submitted from various sources. This can pose a problem with regards to sample names.There may be duplicate sample names, and/or various name formats, all of which make it hard for lab scientists to recognize a sample.

Clarity LIMS programmers often rename all incoming samples to a certain naming convention.

This section provides an example to address this problem.

### Recommendations <a href="#recommendations" id="recommendations"></a>

* When accepting a project and its samples, the receiving lab scientist runs a Clarity LIMS step named **Receive Samples**.
* The underlying **Receive Samples** process type / master step is configured with analyte (sample) inputs, and no analyte outputs.
* A shared result file output is configured to capture logging from the script.
* The sample name could be a derivative of the **Sample LIMSID**, with a prefix:
  * Because the LIMSID is guaranteed to be unique, this approach mitigates any need to maintain an external sequence of numbers.
  * The **Sample LIMSID** is derived from the **Project LIMSID**, which is configurable.

### Proposed solution

* The **Receive Samples** process is configured to trigger a script that renames the samples that are input to the process.
* This trigger also passes the **OriginatingProcessURI** to the script. This example assumes that the original submitted sample name must be preserved, and so it is saved in a sample UDF.

The following pseudo code shows how one might implement the sample-renaming script:

1. Connect to the API, using the **OriginatingProcessURI**.
2. Retrieve the **OriginatingProcessXML** and store it in a variable.
3. Iterate through the **inputoutput map** of the **OriginatingProcessXML**, and for each **InputArtifact**:
   * GET the **InputArtifactURI** and store the input **ArtifactXML** in a variable.
   * From this **ArtifactXML**, GET the **SourceSampleXML** and store it in another variable.
   * Modify the **SourceSampleXML**. To do this:
   * Rename the **SampleName** to a desired name (see Recommendations section, above).
   * Finally, PUT the **Sample XML** back.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.connected.illumina.com/clarity-lims/api-and-database/api-docs/tips-and-tricks/standardizing-sample-naming-via-the-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
