# Create Event

## Create Event

<mark style="color:green;">`POST`</mark> `https://environment.monterosa.cloud/api/v2/events`

#### Headers

| Name                                            | Type   | Description                             |
| ----------------------------------------------- | ------ | --------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb |
| Content-Type<mark style="color:red;">\*</mark>  | string | application/vnd.api+json                |

#### Request Body

| Name                                          | Type    | Description                                                                                                            |
| --------------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------- |
| name<mark style="color:red;">\*</mark>        | string  | Event name.                                                                                                            |
| duration<mark style="color:red;">\*</mark>    | integer | Event duration in seconds.                                                                                             |
| start\_at<mark style="color:red;">\*</mark>   | integer | Planned event start time (timestamp).                                                                                  |
| start\_mode<mark style="color:red;">\*</mark> | string  | Start mode, one of : "manual", "clock".                                                                                |
| repeat                                        | boolean | `true` to say this event has to be automatically recreated after it's finished.                                        |
| repeat\_in                                    | integer | Repeat event will be automatically created in repeat\_in minutes after end of original event.                          |
| settings                                      | array   | List of fields of event settings. Each field is updated separately and if present its content is rewritten completely. |
| action                                        | string  | Set to perform action on event. Possible actions: `start` - start manual event.                                        |
| end\_mode                                     | string  | Event end mode. One of "duration", "scheduled".                                                                        |

{% tabs %}
{% tab title="201 " %}

```javascript
{
  "data": {
    "id": "18b17c20-5e84-4086-8da0-784f21622e16",
    "type": "events",
    "attributes": {
      "name": "Live Event",
      "duration": 3600,
      "start_at": 1458487800,
      "start_at_iso": "2016-03-20T15:30:00Z",
      "start_mode": "manual",
      "end_mode": "duration",
      "repeat": false,
      "settings": [
        {
          "key": "hold_prompt",
          "values": {
            "en": "We'll be back shortly",
            "de": "Wir sind gleich wieder da"
          }
        }
      ],
      "state": "future"
    },
    "links": {
      "self": "https://example.lvis.io/api/v2/events/18b17c20-5e84-4086-8da0-784f21622e16"
    },
    "relationships": {
      "elements": {
        "links": {
          "related": "https://example.lvis.io/api/v2/events/18b17c20-5e84-4086-8da0-784f21622e16/elements"
        }
      },
      "stats": {
        "data": {
          "id": "18b17c20-5e84-4086-8da0-784f21622e16",
          "type": "stats"
        }
      },
      "project": {
        "data": {
          "id": "850e644e-f1ea-444d-bae3-cf38badbe501",
          "type": "projects"
        }
      }
    }
  }
}
```

{% endtab %}
{% endtabs %}

## Create Event

<mark style="color:green;">`POST`</mark> `https://environment.monterosa.cloud/api/v2/events`

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | string | l0gVURLT5MSG |
| Content-Type<mark style="color:red;">\*</mark>  | string | jC0pJgVvaRez |

#### Request Body

| Name                                          | Type    | Description  |
| --------------------------------------------- | ------- | ------------ |
| name<mark style="color:red;">\*</mark>        | string  | Rru6E9cNrwMM |
| duration<mark style="color:red;">\*</mark>    | integer | ynFRpKtMu1dd |
| start\_at<mark style="color:red;">\*</mark>   | integer | 2rkZo70YXc2p |
| start\_mode<mark style="color:red;">\*</mark> | string  | g3akxzkckjw4 |
| repeat                                        | boolean | FziJr1EXJKoi |
| repeat\_in                                    | integer | nvEFFVNVMdMI |
| settings                                      | array   | 3zopTTH1dlw0 |
| action                                        | string  | PeCtM00JQxAI |
| end\_mode                                     | string  | 6b4AMZ1ZF0aW |

## Example

{% tabs %}
{% tab title="Request" %}

```javascript
// POST /api/v2/events
// Host: environment.monterosa.cloud
// Authorization: Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb
// Content-Type: application/vnd.api+json

{
  "data": {
    "type": "events",
    "relationships": {
      "project": {
        "data": {
          "type": "projects",
          "id": "850e644e-f1ea-444d-bae3-cf38badbe501"
        }
      }
    },
    "attributes": {
      "name": "Live Event",
      "duration": 3600,
      "start_at": 1458487800,
      "start_mode": "manual",
      "end_mode": "scheduled",
      "repeat": false,
      "settings": [
        {
          "key": "hold_prompt",
          "values": {
            "en": "We will be back shortly",
            "de": "Wir sind gleich wieder da"
          }
        },
        {
          "key": "advert_code",
          "values": {
            "all" : "Advert code"
          }
        }
      ]
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
// Status: 201 Created

{
  "data": {
    "id": "18b17c20-5e84-4086-8da0-784f21622e16",
    "type": "events",
    "attributes": {
      "name": "Live Event",
      "duration": 3600,
      "start_at": 1458487800,
      "start_at_iso": "2016-03-20T15:30:00Z",
      "start_mode": "manual",
      "end_mode": "scheduled",
      "repeat": false,
      "settings": [
        {
          "key": "hold_prompt",
          "values": {
            "en": "We will be back shortly",
            "de": "Wir sind gleich wieder da"
          }
        }
      ],
      "state": "future"
    },
    "links": {
      "self": "https://environment.monterosa.cloud/api/v2/events/18b17c20-5e84-4086-8da0-784f21622e16"
    },
    "relationships": {
      "elements": {
        "links": {
          "related": "https://environment.monterosa.cloud/api/v2/events/18b17c20-5e84-4086-8da0-784f21622e16/elements"
        }
      },
      "stats": {
        "data": {
          "id": "18b17c20-5e84-4086-8da0-784f21622e16",
          "type": "stats"
        }
      },
      "project": {
        "data": {
          "id": "850e644e-f1ea-444d-bae3-cf38badbe501",
          "type": "projects"
        }
      }
    }
  }
}
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request POST \
  --url https://environment.monterosa.cloud/api/v2/events \
  --header 'Authorization: Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb' \
  --header 'Content-Type: application/vnd.api+json' \
  --data '{
    "data": {
      "type": "events",
      "relationships": {
        "project": {
          "data": {
            "type": "projects",
            "id": "850e644e-f1ea-444d-bae3-cf38badbe501"
          }
        }
      },
      "attributes": {
        "name": "Live Event",
        "duration": 3600,
        "start_at": 1458487800,
        "start_mode": "manual",
        "end_mode": "scheduled",
        "repeat": false,
        "settings": [
          {
            "key": "hold_prompt",
            "values": {
              "en": "We will be back shortly",
              "de": "Wir sind gleich wieder da"
            }
          },
          {
            "key": "advert_code",
            "values": {
              "all" : "Advert code"
            }
          }
        ]
      }
    }
  }'
```

{% endtab %}
{% endtabs %}

### Create an event and start it

To start new event `action` must be set to `start`. Otherwise event will be started according to `start_mode` and `start_at` properties.

{% tabs %}
{% tab title="Request" %}

```javascript
// POST /api/v2/events
// Host: environment.monterosa.cloud
// Authorization: Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb
// Content-Type: application/vnd.api+json

{
  "data": {
    "type": "events",
    "relationships": {
      "project": {
        "data": {
          "type": "projects",
          "id": "f1b50562-edae-43e9-8f4f-4f8e6765ef91"
        }
      }
    },
    "attributes": {
      "name": "Event Name",
      "start_mode": "manual",
      "duration": 60,
      "action": "start",
      "start_at": 1458487800,
      "settings": []
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
// Status: 201 Created

{
  "data": {
    "id": "6926723a-dddb-4519-a631-1f616a90f78f",
    "type": "events",
    "attributes": {
      "name": "Event Name",
      "duration": 60,
      "original_duration": 60,
      "start_mode": "manual",
      "repeat": false,
      "repeat_in": null,
      "feed_uuid": "af4c1b02-c6bc-47c6-a6b9-0e186721537b",
      "live_stats_uuid": null,
      "extra_time": 60,
      "start_at": 1458487800,
      "start_at_iso": "2016-03-20T15:30:00Z",
      "end_at": 1458487860,
      "end_at_iso": "2016-03-20T15:31:00Z",
      "settings": [],
      "state": "future",
      "actions": []
    },
    "relationships": {
      "elements": {
        "links": {
          "related": "https://environment.monterosa.cloud/api/v2/events/6926723a-dddb-4519-a631-1f616a90f78f/elements"
        }
      },
      "stats": {
        "data": {
          "id": "6926723a-dddb-4519-a631-1f616a90f78f",
          "type": "stats"
        }
      },
      "project": {
        "data": {
          "id": "f1b50562-edae-43e9-8f4f-4f8e6765ef91",
          "type": "projects"
        }
      }
    },
    "links": {
      "self": "https://environemnt.monterosa.cloud/api/v2/events/6926723a-dddb-4519-a631-1f616a90f78f"
    }
  }
}
```

{% endtab %}
{% endtabs %}

### Validation error message about an invalid attribute

{% tabs %}
{% tab title="Request" %}

```javascript
// POST /api/v2/events
// Host: environment.monterosa.cloud
// Authorization: Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb
// Content-Type: application/vnd.api+json

{
  "data": {
    "type": "events",
    "relationships": {
      "project": {
        "data": {
          "type": "projects",
          "id": "4c7ec57b-b03f-4c6c-b52c-ced4b3ef23c1"
        }
      }
    },
    "attributes": {
      "name": "Event Name",
      "start_mode": "manual",
      "duration": -1,
      "start_at": 1458487800,
      "settings": []
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
// Status: 422 Unprocessable Entity

{
  "errors": [
    {
      "source": {
        "pointer": "/data/attributes/duration"
      },
      "detail": "must be greater than 0"
    }
  ]
}
```

{% endtab %}
{% endtabs %}
