# Update Element

## &#x20;Update Element

<mark style="color:purple;">`PATCH`</mark> `https://environment.lvis.io/api/v2/elements/:element_id`

#### Path Parameters

| Name        | Type   | Description |
| ----------- | ------ | ----------- |
| element\_id | string | Element ID. |

#### Headers

| Name          | Type   | Description                             |
| ------------- | ------ | --------------------------------------- |
| Authorization | string | Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb |
| Content-Type  | string | application/vnd.api+json                |

#### Request Body

| Name                               | Type    | Description                                                                                                                                                                                                                                                     |
| ---------------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| duration                           | integer | Element duration in seconds. Required for elements with duration.                                                                                                                                                                                               |
| start\_mode                        | string  | Start mode. Possible values: "manual", "timecode".                                                                                                                                                                                                              |
| offset                             | integer | Element offset from event start in seconds. Required only for the "timecode" start mode.                                                                                                                                                                        |
| action                             | string  | Set to perform an action on element. Possible actions: "stop" - stop an active element; "reveal\_answer" - reveal the answer of a quiz-element; "reveal\_results" - reveal results of an element; "revoke" - revoke an element; "publish" - publish an element. |
| question                           | object  | Question (with options) for poll-like elements.                                                                                                                                                                                                                 |
| correct\_option                    | integer | Number of correct option. Available only for prediction and trivia.                                                                                                                                                                                             |
| reveal\_results\_mode              | string  | Set when the results will be revealed to the client. Only for poll-like elements. Possible values: "vote", "close", "event\_end", "never", "manual".                                                                                                            |
| require\_verified\_user            | boolean | Sets mode when only verified user can vote.                                                                                                                                                                                                                     |
| include\_in\_latest\_results\_feed | boolean | Include element results in latest results feed.                                                                                                                                                                                                                 |
| certification                      | boolean | Enables votes certification for poll-like elements.                                                                                                                                                                                                             |
| max\_votes\_per\_user              | string  | Maximum number of votes per user.                                                                                                                                                                                                                               |
| max\_votes\_per\_option            | integer | Maximum number of votes a user can cast per option.                                                                                                                                                                                                             |
| min\_options\_per\_vote            | integer | Minimum options count allowed to vote.                                                                                                                                                                                                                          |
| max\_options\_per\_vote            | integer | Maximum options count allowed to vote.                                                                                                                                                                                                                          |
| reveal\_answer\_mode               | string  | Reveal answer mode for quiz elements. Possible values: "auto", "manual".                                                                                                                                                                                        |
| reveal\_answer\_in                 | integer | Answer reveal delay in seconds in auto mode for quiz elements.                                                                                                                                                                                                  |
| fade                               | integer | A number of seconds between user's vote and when this vote will be faded out.                                                                                                                                                                                   |
| custom\_fields                     | array   | List of an element's custom fields. Each field is updated separately and if present its content is rewritten completely.                                                                                                                                        |
| reveal\_answer\_on\_vote           | boolean | Enables reveal answer on vote for quiz elements.                                                                                                                                                                                                                |

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

```javascript
// no content
```

{% endtab %}
{% endtabs %}

## Example

### Update attributes for an element

{% hint style="warning" %}
Update attributes possible only for non-published elements.
{% endhint %}

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

```javascript
// PATCH /api/v2/elements/85ce5d32-a6b4-4219-bc72-4fcf18f2a5dc
// Host: environment.monterosa.cloud
// Authorization: Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb
// Content-Type: application/vnd.api+json

{
  "data": {
    "id": "85ce5d32-a6b4-4219-bc72-4fcf18f2a5dc",
    "type": "elements",
    "attributes": {
      "question": {
        "fields": [
          {
            "key": "text",
            "values": {
              "en": "Another Question Text"
            }
          }
        ],
        "options": [
          {
            "fields": [
              {
                "key": "text",
                "values": {
                  "en": "Another Option Text #1"
                }
              }
            ]
          },
          {
            "fields": [
              {
                "key": "text",
                "values": {
                  "en": "Another Option Text #2"
                }
              }
            ]
          }
        ]
      }
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
// Status: 204 No Content
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request PATCH \
  --url https://environment.monterosa.cloud/api/v2/elements/85ce5d32-a6b4-4219-bc72-4fcf18f2a5dc \
  --header 'Authorization: Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb' \
  --header 'Content-Type: application/vnd.api+json' \
  --data '{
    "data": {
      "id": "85ce5d32-a6b4-4219-bc72-4fcf18f2a5dc",
      "type": "elements",
      "attributes": {
        "question": {
          "fields": [
            {
              "key": "text",
              "values": {
                "en": "Another Question Text"
              }
            }
          ],
          "options": [
            {
              "fields": [
                {
                  "key": "text",
                  "values": {
                    "en": "Another Option Text #1"
                  }
                }
              ]
            },
            {
              "fields": [
                {
                  "key": "text",
                  "values": {
                    "en": "Another Option Text #2"
                  }
                }
              ]
            }
          ]
        }
      }
    }
  }'
```

{% endtab %}
{% endtabs %}

In current example we change the question and options texts.

### Publish an element

{% hint style="warning" %}
Element can be published for the active event only.
{% endhint %}

{% hint style="info" %}
Element published via passing "publish" for action attribute.&#x20;
{% endhint %}

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

```javascript
// PATCH /api/v2/elements/37e27fe2-845a-4574-92ad-ff97f44edcba
// Host: environment.monterosa.cloud
// Authorization: Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb
// Content-Type: application/vnd.api+json

{
  "data": {
    "id": "37e27fe2-845a-4574-92ad-ff97f44edcba",
    "type": "elements",
    "attributes": {
      "action": "publish"
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
// Status: 204 No Content
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request PATCH \
  --url https://environment.monterosa.cloud/api/v2/elements/85ce5d32-a6b4-4219-bc72-4fcf18f2a5dc \
  --header 'Authorization: Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb' \
  --header 'Content-Type: application/vnd.api+json' \
  --data '{
    "data": {
      "id": "37e27fe2-845a-4574-92ad-ff97f44edcba",
      "type": "elements",
      "attributes": {
        "action": "publish"
      }
    }
  }'
```

{% endtab %}
{% endtabs %}

### Reveal answer

Reveal an answer for elements with manual reveal answer mode is possible via passing "reveal\_answer" like the "action" attribute.

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

```javascript
// PATCH /api/v2/elements/37e27fe2-845a-4574-92ad-ff97f44edcba
// Host: environment.monterosa.cloud
// Authorization: Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb
// Content-Type: application/vnd.api+json

{
  "data": {
    "id": "37e27fe2-845a-4574-92ad-ff97f44edcba",
    "type": "elements",
    "attributes": {
      "action": "reveal_answer",
      "correct_option": 1
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
// Status: 204 No Content
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request PATCH \
  --url https://environment.monterosa.cloud/api/v2/elements/85ce5d32-a6b4-4219-bc72-4fcf18f2a5dc \
  --header 'Authorization: Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb' \
  --header 'Content-Type: application/vnd.api+json' \
  --data '{
    "data": {
      "id": "37e27fe2-845a-4574-92ad-ff97f44edcba",
      "type": "elements",
      "attributes": {
        "action": "reveal_answer",
        "correct_option": 1
      }
    }
  }'
```

{% endtab %}
{% endtabs %}

### Validation error message about invalid `custom_fields`

When we are trying to update a field that doesn't exist in the element spec.

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

```javascript
// PATCH /api/v2/elements/00b32a9c-ee68-4744-82d7-1812e80a14bb
// Host: environment.monterosa.cloud
// Authorization: Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb
// Content-Type: application/vnd.api+json

{
  "data": {
    "id": "00b32a9c-ee68-4744-82d7-1812e80a14bb",
    "type": "elements",
    "attributes": {
      "custom_fields": [
        {
          "key": "INVALID_text",
          "values": {
            "en": "New Text 2"
          }
        }
      ]
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
// Status: 422 Unprocessable Entity

{
  "errors": [
    {
      "source": {
        "pointer": "/data/attributes/custom_fields/0/key"
      },
      "detail": "field must be specified in the settings spec"
    }
  ]
}
```

{% endtab %}
{% endtabs %}
