# Create Label Set

When creating a Span Labeling Project, you may also want to set up a label set.\
The example below shows how to create a simple label set with three labels, each assigned a color.

In this case, we’ll use the GraphQL mutation **`createLabelSet`** to create the label set in Datasaur.

**Mutation**: [createLabelSet](https://api-docs.datasaur.ai/#mutation-createLabelSet).

## cURL

Use the following cURL command to create a label set and attach it to a project. Copy and paste it, then replace the following:

* **`access_token`** with your own API access token.
* **The content of the label set items** with your desired labels.
* **`project_id`** with the ID of the project you want to link it to.

Make sure to adjust these values according to your specific needs before running the command.

```sh
curl --location --request POST 'https://datasaur.ai/graphql' \
--header 'Authorization: Bearer access_token' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"mutation CreateLabelSetMutation($input: CreateLabelSetInput!, $projectId: ID!) { createLabelSet(input: $input, projectId: $projectId) { id }}","variables":{"input":{"name":"Give your new label set a name","index":0,"tagItems":[{"id":"per","parentId":null,"desc":null,"color":"red","tagName":"PER"},{"id":"geo","parentId":null,"desc":null,"color":"green","tagName":"GEO"},{"id":"gpe","parentId":null,"desc":null,"color":null,"tagName":"GPE"}]},"projectId":"<projectId>"}}'
```

For clarity, here’s a formatted version of the request body:

{% code overflow="wrap" lineNumbers="true" %}

```json
{
  "query": "mutation CreateLabelSetMutation($input: CreateLabelSetInput!, $projectId: ID!) { createLabelSet(input: $input, projectId: $projectId) { id }}",
  "variables": {
    "projectId": "<projectId>",
    "input": {
      "name": "Give your new label set a name",
      "index": 0,
      "tagItems": [
        {
          "id": "per",
          "parentId": null,
          "desc": null,
          "color": "red",
          "tagName": "PER"
        },
        {
          "id": "geo",
          "parentId": null,
          "desc": null,
          "color": "green",
          "tagName": "GEO"
        },
        {
          "id": "gpe",
          "parentId": null,
          "desc": null,
          "color": null,
          "tagName": "GPE"
        }
      ]
    }
  }
}

```

{% endcode %}

* **operationName**: you can fill any alphanumeric string in as the operationName. Refer to [this page](https://graphql.org/learn/queries/#operation-name) for best practices on choosing an `operationName` .
* **variables:**
  * **projectId**: optional, but in practice this is required if you want to attach the label set to a particular project. If unspecified, the label set will be created, but you won't be able to see it in the project
  * **input:**
    * **name:** optional, You may give this label set a name so you could refer it in the future from Label Set Library.
    * **index:** optional, index or position of the label set. Zero-based index, to set the label set as the first one, set this value as **0**
    * **tagItems:**
      * Each tag item includes 3 required fields
        * **id**: Fill with a random id. You can use any string as long as it is unique.
        * **parentId**: This is used for hierarchical labels. Use any existing ids that you have defined. If there is no parentId, use `null`.
        * **tagName**: Fill with the actual labels you'd like to use and the user will see e.g. `person`, `geopolitical entity`
      * A tag item also has 2 optional fields
        * **desc**: label description
        * **color:** You can set the color of the label. Refer to [this page](/data-studio-projects/lets-get-labeling/label-sets.md#color-coded-labels).
* **query**: Copy this from the cURL example.

{% hint style="info" %}
A **tag** has the same meaning as **label**. In the near future we will update the GraphQL Schema to refer to all instances as labels.
{% endhint %}

## Response

Here is the response you can expect after issuing the cURL command. Use the **id** to create the project.

```json
{
    "data": {
        "createLabelSet": {
            "id": "366"
        }
    },
    "extensions": {}
}
```


---

# 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://docs.datasaur.ai/api/labeling/create-label-set.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.
