# Add tag

Add a new resource tag for this entity.

Required permission: Account > Tags > General > Create

**Request body:**

{object}
- `useSpotNodes`: (boolean) Schedule workloads to spot nodes
- `useOnDemandNodes`: (boolean) Also allow workloads to schedule to on demand nodes. Only relevant if you want workloads to schedule across both spot and on demand nodes
- `nodeAffinities`: [array of] {object}
   - `preference`: (boolean)
   - `weight`: (number) The node affinity weight. Required when `preference` is `true`. (format: float)
   - `matchExpressions`: [array of] {object}
      - `key`: (string) (required)
      - `operator`: (string) (required) (enum: In, NotIn)
      - `values`: [array of] (string)
- `color`: (string) (pattern: ^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$)
- `description`: (string) (pattern: ^[a-zA-Z0-9.,?\s\\/'"()[\];`%^&*\-_:!]+$) (max length: 200)
- `name`: (string) (required) (pattern: ^[a-zA-Z0-9]+((-|\s)[a-zA-Z0-9]+)*$) (min length: 3) (max length: 100)

**Response body:**

{object}
- `data`: {object}
  - `useSpotNodes`: (boolean) Schedule workloads to spot nodes
  - `useOnDemandNodes`: (boolean) Also allow workloads to schedule to on demand nodes. Only relevant if you want workloads to schedule across both spot and on demand nodes
  - `nodeAffinities`: [array of] {object}
     - `preference`: (boolean)
     - `weight`: (number) The node affinity weight. Required when `preference` is `true`. (format: float)
     - `matchExpressions`: [array of] {object}
         - `key`: (string) (required)
         - `operator`: (string) (required) (enum: In, NotIn)
         - `values`: [array of] (string)
  - `color`: (string) (pattern: ^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$)
  - `description`: (string) (pattern: ^[a-zA-Z0-9.,?\s\\/'"()[\];`%^&*\-_:!]+$) (max length: 200)
  - `name`: (string) (required) (pattern: ^[a-zA-Z0-9]+((-|\s)[a-zA-Z0-9]+)*$) (min length: 3) (max length: 100)
  - `id`: (string) (required) (pattern: ^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$) (min length: 3) (max length: 100)
  - `createdAt`: (string) time of creation (format: date-time)

## API reference

POST /v1/tags

POST /v1/teams/{teamId}/tags

### Example request

Request body

```curl
curl --header "Content-Type: application/json" \
  --header "Authorization: Bearer NORTHFLANK_API_TOKEN" \
  --request POST \
  --data '{"useSpotNodes":false,"useOnDemandNodes":false,"color":"#57637A","name":"Example Tag"}' \
  https://api.northflank.com/v1/tags
```

```javascript
const payload = {
  "useSpotNodes": false,
  "useOnDemandNodes": false,
  "color": "#57637A",
  "name": "Example Tag"
}

const response = await fetch('https://api.northflank.com/v1/tags', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${NORTHFLANK_API_TOKEN}`
  },
  body: JSON.stringify(payload)
})

const json = await response.json()
console.log(json)
```

```python
import requests

url = "https://api.northflank.com/v1/tags"

payload = {"useSpotNodes":false,"useOnDemandNodes":false,"color":"#57637A","name":"Example Tag"}
headers = {"Content-Type": "application/json", "Authorization": "Bearer NORTHFLANK_API_TOKEN"}

response = requests.request("POST", url, headers = headers, json = payload)

print(response.json())
```

```go
package main

import (
  "bytes"
  "fmt"
  "io/ioutil"
  "net/http"
)

func main() {
  url := "https://api.northflank.com/v1/tags"

  var jsonStr = []byte(`{"useSpotNodes":false,"useOnDemandNodes":false,"color":"#57637A","name":"Example Tag"}`)
  req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
  req.Header.Set("Content-Type", "application/json")
  req.Header.Set("Authorization", "Bearer NORTHFLANK_API_TOKEN")

  client := &http.Client{}
  resp, err := client.Do(req)
  if err != nil {
    panic(err)
  }
  defer resp.Body.Close()

  fmt.Println("Response status:", resp.Status)
  fmt.Println("Response headers:", resp.Header)
  body, _ := ioutil.ReadAll(resp.Body)
  fmt.Println("Response body:", string(body))
}
```

### Example Response

200 OK: Data about the newly created tag.

```json
{
  "data": {
    "useSpotNodes": false,
    "useOnDemandNodes": false,
    "color": "#57637A",
    "name": "Example Tag",
    "id": "example-tag",
    "createdAt": "2000-01-01T12:00:00.000Z"
  }
}
```

## CLI reference

$ northflank add tag

Options:

- `-f --file <file>`: Path to a JSON/YAML resource definition file

- `-i --input <definition>`: JSON/YAML resource definition string (takes precedence over --file)

- `--verbose `: Verbose output

- `--quiet `: No console output

- `-o --output <format>`: Output formatting 

```json
{
  "useSpotNodes": false,
  "useOnDemandNodes": false,
  "color": "#57637A",
  "name": "Example Tag"
}
```

### Example Response

 Data about the newly created tag.

```json
{
  "useSpotNodes": false,
  "useOnDemandNodes": false,
  "color": "#57637A",
  "name": "Example Tag",
  "id": "example-tag",
  "createdAt": "2000-01-01T12:00:00.000Z"
}
```

## JavaScript client reference

### Example request

Request body

```javascript
await apiClient.add.tag({
  data: {
    "useSpotNodes": false,
    "useOnDemandNodes": false,
    "color": "#57637A",
    "name": "Example Tag"
  }    
});
```

### Example Response

 Data about the newly created tag.

```json
{
  "data": {
    "useSpotNodes": false,
    "useOnDemandNodes": false,
    "color": "#57637A",
    "name": "Example Tag",
    "id": "example-tag",
    "createdAt": "2000-01-01T12:00:00.000Z"
  },
  "rawResponse": "...",
  "request": "...",
  "error": "..."
}
```

Previous: [List tags](/docs/v1/api//team/tags/list-tags)

Next: [Put tag](/docs/v1/api//team/tags/put-tag)