> For the complete documentation index, see [llms.txt](https://help.claritylims.illumina.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.claritylims.illumina.com/api-and-database/api-docs/tips-and-tricks/creating-samples-and-projects-via-the-api.md).

# Creating Samples and Projects via the API

### Assumptions

The incoming message contains the following:

* Project ID or Name
* Sample ID or Name
* Container ID or Name
* Container type (plate / tube type)
* Container well position (if sample is on a plate) eg G:2
* Sample user-defined fields (UDFs) / custom fields

### Main Logic <a href="#logic" id="logic"></a>

```
Does the project exist?
    if NO: create it
Does the container exist?
    if NO: create it
Create sample
```

### Create a Sample: <a href="#createsample" id="createsample"></a>

**POST** to <https://your\\_server/api/v2/samples>:

```
<?xml version="1.0" encoding="UTF-8"?>
<smp:samplecreation xmlns:smp="http://genologics.com/ri/sample" xmlns:udf="http://genologics.com/ri/userdefined">
    <name>20140909-1</name>
    <project uri="https://your_server/api/v2/projects/ROS210"></project>
    <location>
        <container uri="https://your_server/api/v2/containers/27-195"></container>
        <value>1:1</value>
    </location>
    <udf:field name="Reference Genome">Cane Toad</udf:field>
</smp:samplecreation>
```

We receive something like the following:

```
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<smp:sample uri="https://your_server/api/v2/samples/ROS210A14" limsid="ROS210A14">
    <name>20140909-1</name>
    <date-received>2014-09-10</date-received>
    <project limsid="ROS210" uri="https://your_server/api/v2/projects/ROS210" />
    <submitter uri="https://your_server/api/v2/researchers/1">
        <first-name>System</first-name>
        <last-name>Administrator</last-name>
    </submitter>
    <artifact limsid="ROS210A14PA1" uri="https://your_server/api/v2/artifacts/ROS210A14PA1?state=4262" />
    <udf:field type="String" name="Reference Genome">Cane Toad</udf:field>
</smp:sample>
```

#### Create a Project: <a href="#createproject" id="createproject"></a>

**POST** to <https://your\\_server/api/v2/projects>

```
<?xml version="1.0" encoding="UTF-8"?>
<prj:project xmlns:udf="http://genologics.com/ri/userdefined" xmlns:ri="http://genologics.com/ri" xmlns:file="http://genologics.com/ri/file" xmlns:prj="http://genologics.com/ri/project">
      <name>Week 39</name>
      <open-date>2014-09-10</open-date>
      <researcher uri="https://your_server/api/v2/researchers/1"/>
</prj:project>
```

We receive something like the following:

<pre><code>&#x3C;?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<strong>&#x3C;prj:project uri="https://your_server/api/v2/projects/ADM372" limsid="ADM372">
</strong>    &#x3C;name>Week 39&#x3C;/name>
    &#x3C;open-date>2014-09-10&#x3C;/open-date>
    &#x3C;researcher uri="https://your_server/api/v2/researchers/1" />
&#x3C;/prj:project> 
</code></pre>

#### Create a Container (tube): <a href="#createtube" id="createtube"></a>

**POST** to <https://your\\_server/api/v2/containers>:

```
<?xml version="1.0" encoding="UTF-8"?>
<con:container xmlns:con="http://genologics.com/ri/container">
      <name>Example Container 20140910</name>
      <type uri="https://your_server/api/v2/containertypes/2" name="Tube"/>
</con:container>
```

We receive something like the following:

<pre><code>&#x3C;?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<strong>&#x3C;con:container uri="https://your_server/api/v2/containers/27-1869" limsid="27-1869">
</strong>    &#x3C;name>Example Container 20140910&#x3C;/name>
    &#x3C;type uri="https://your_server/api/v2/containertypes/2" name="Tube" />
    &#x3C;occupied-wells>0&#x3C;/occupied-wells>
    &#x3C;state>Empty&#x3C;/state>
&#x3C;/con:container>
</code></pre>

#### Create a Container (96 well plate): <a href="#createplate" id="createplate"></a>

**POST** to <https://your\\_server/api/v2/containers>:

```
<?xml version="1.0" encoding="UTF-8"?>
<con:container xmlns:con="http://genologics.com/ri/container">
    <name>Example Plate 20140910</name>
    <type uri="https://your_server/api/v2/containertypes/1" name="96 well plate"/>
</con:container> 
```

We receive something like the following:

<pre><code>&#x3C;?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<strong>&#x3C;con:container uri="https://your_server/api/v2/containers/27-1870" limsid="27-1870">
</strong>    &#x3C;name>Example Plate 20140910&#x3C;/name>
    &#x3C;type uri="https://your_server/api/v2/containertypes/1" name="96 well plate" />
    &#x3C;occupied-wells>0&#x3C;/occupied-wells>
    &#x3C;state>Empty&#x3C;/state>
&#x3C;/con:container> 
</code></pre>

#### Create a Sample in the 96 Well Plate Rreated, and the Project Created: <a href="#createsampleinplate" id="createsampleinplate"></a>

**POST** to <https://your\\_server/api/v2/samples>:

<pre><code>&#x3C;?xml version="1.0" encoding="UTF-8"?>
&#x3C;smp:samplecreation xmlns:smp="http://genologics.com/ri/sample" xmlns:udf="http://genologics.com/ri/userdefined">
      &#x3C;name>20140909-1&#x3C;/name>
<strong>      &#x3C;project uri="https://your_server/api/v2/projects/ADM372">&#x3C;/project>
</strong>      &#x3C;location>
<strong>            &#x3C;container uri="https://your_server/api/v2/containers/27-1870">&#x3C;/container>
</strong>            &#x3C;value>G:2&#x3C;/value>
      &#x3C;/location>
      &#x3C;udf:field name="Reference Genome">Cane Toad&#x3C;/udf:field>
&#x3C;/smp:samplecreation>
</code></pre>

We receive something like the following:

<pre><code>&#x3C;?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
&#x3C;smp:sample uri="https://your_server/api/v2/samples/ADM372A2" limsid="ADM372A2">
    &#x3C;name>20140909-1&#x3C;/name>
    &#x3C;date-received>2014-09-10&#x3C;/date-received>
<strong>    &#x3C;project limsid="ADM372" uri="https://your_server/api/v2/projects/ADM372" />
</strong>     &#x3C;submitter uri="https://your_server/api/v2/researchers/1">
        &#x3C;first-name>System&#x3C;/first-name>
        &#x3C;last-name>Administrator&#x3C;/last-name>
    &#x3C;/submitter>
    &#x3C;artifact limsid="ADM372A2PA1" uri="https://your_server/api/v2/artifacts/ADM372A2PA1?state=4264" />
    &#x3C;udf:field type="String" name="Reference Genome">Cane Toad&#x3C;/udf:field>
 &#x3C;/smp:sample>
</code></pre>

#### Confirm the Project Exists <a href="#confirmproject" id="confirmproject"></a>

**GET**: <https://your\\_server/api/v2/projects?name=**Week%2039>\*\*

If the project exists, we receive something like the following:

<pre><code>&#x3C;prj:projects xmlns:prj="http://genologics.com/ri/project">
    &#x3C;project uri="https://your_server/api/v2/projects/ADM372" limsid="ADM372">
<strong>        &#x3C;name>Week 39&#x3C;/name>
</strong>    &#x3C;/project>
&#x3C;/prj:projects>
</code></pre>

If the project does not exist, we receive something like the following:

```
<prj:projects xmlns:prj="http://genologics.com/ri/project"/>
```

#### Confirm the Container Exists <a href="#confirmcontainer" id="confirmcontainer"></a>

**GET:** <https://your\\_server/api/v2/containers?name=**Example%20Container%2020140910>\*\*

If the container exists, we receive something like the following:

<pre><code>&#x3C;con:containers xmlns:con="http://genologics.com/ri/container">
<strong>    &#x3C;container uri="https://your_server/api/v2/containers/27-1869" limsid="27-1869">
</strong><strong>        &#x3C;name>Example Container 20140910&#x3C;/name>
</strong>    &#x3C;/container>
&#x3C;/con:containers>
</code></pre>

If the container does not exist, we receive something like the following:

```
<con:containers xmlns:con="http://genologics.com/ri/container"/>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://help.claritylims.illumina.com/api-and-database/api-docs/tips-and-tricks/creating-samples-and-projects-via-the-api.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
