# SurveyAnswerOptions

## Introduction

`SurveyAnswerOptions` represent the selectable answer choices for a [Survey](https://docs.api.intratool.de/api-reference/surveys/surveys). Answer options can be sorted and are protected from modification if the survey already has [SurveyVotes](https://docs.api.intratool.de/api-reference/surveys/survey-votes).

## Model Definition

### Alias

`surveyAnswerOption`

### Relations

| Key      | Relation                                                              | Type       | Relation Field(s) |
| -------- | --------------------------------------------------------------------- | ---------- | ----------------- |
| `user`   | [User](https://docs.api.intratool.de/api-reference/users)             | Belongs to | `user_id`         |
| `survey` | [Survey](https://docs.api.intratool.de/api-reference/surveys/surveys) | Belongs to | `survey_id`       |

## List by Survey

Get a list of all `SurveyAnswerOptions` for a given [Survey](https://docs.api.intratool.de/api-reference/surveys/surveys) and the authenticated user.

**Definition**

<mark style="color:green;">`GET`</mark> `/api/surveys/{survey}/answer-options`

**Example Request**

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

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/surveys/1/answer-options', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
[
  {
    "id": 1,
    "user_id": 2,
    "survey_id": 1,
    "lang_id": "en-US",
    "title": "Very satisfied",
    "sort_number": 1,
    "created_at": "2024-07-15 12:00:00",
    "updated_at": "2024-07-15 12:00:00",
    "deleted_at": null
  },
  {
    "id": 2,
    "user_id": 2,
    "survey_id": 1,
    "lang_id": "en-US",
    "title": "Satisfied",
    "sort_number": 2,
    "created_at": "2024-07-15 12:00:000",
    "updated_at": "2024-07-15 12:00:00",
    "deleted_at": null
  }
]
```

## Show

Show a single `SurveyAnswerOption` by `id`.

**Definition**

<mark style="color:green;">`GET`</mark> `/api/administration/surveys/{survey}/answer-options/{id}`

**Example Request**

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

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/administration/surveys/1/answer-options/1', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "id": 1,
  "user_id": 2,
  "survey_id": 1,
  "lang_id": "en-US",
  "title": "Very satisfied",
  "sort_number": 1,
  "created_at": "2024-07-15 12:00:00",
  "updated_at": "2024-07-15 12:00:00",
  "deleted_at": null
}
```

## \[Adm.] List by Survey

Get a list of all `SurveyAnswerOptions` for a given [Survey](https://docs.api.intratool.de/api-reference/surveys/surveys).

**Definition**

<mark style="color:green;">`GET`</mark> `/api/administration/surveys/{survey}/answer-options`

**Example Request**

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

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/administration/surveys/1/answer-options', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
[
  {
    "id": 1,
    "user_id": 2,
    "survey_id": 1,
    "lang_id": "en-US",
    "title": "Very satisfied",
    "sort_number": 1,
    "created_at": "2024-07-15 12:00:00",
    "updated_at": "2024-07-15 12:00:00",
    "deleted_at": null
  },
  {
    "id": 2,
    "user_id": 2,
    "survey_id": 1,
    "lang_id": "en-US",
    "title": "Satisfied",
    "sort_number": 2,
    "created_at": "2024-07-15 12:00:000",
    "updated_at": "2024-07-15 12:00:00",
    "deleted_at": null
  }
]
```

## \[Adm.] Show

Show a single `SurveyAnswerOption` by `id`.

**Definition**

<mark style="color:green;">`GET`</mark> `/api/administration/surveys/{survey}/answer-options/{id}`

**Example Request**

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

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/administration/surveys/1/answer-options/1', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "id": 1,
  "user_id": 2,
  "survey_id": 1,
  "lang_id": "en-US",
  "title": "Very satisfied",
  "sort_number": 1,
  "created_at": "2024-07-15 12:00:00",
  "updated_at": "2024-07-15 12:00:00",
  "deleted_at": null
}
```

## Create

Create a new `SurveyAnswerOption` for a survey.

**Definition**

<mark style="color:yellow;">`POST`</mark> `/api/administration/surveys/{survey}/answer-options`

**Request Keys**

| Key           | Type    | Default            | Description                                                                                                                 |
| ------------- | ------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------- |
| `title` \*    | string  | -                  | The answer option text.                                                                                                     |
| `sort_number` | integer | Current highest +1 | The index of the `SurveyAnswerOption` related to the [Survey](https://docs.api.intratool.de/api-reference/surveys/surveys). |

Keys with `*` are required.

**Example Request**

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

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('POST', '/api/administration/surveys/1/answer-options', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'title' => 'Neutral'
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 3,
    "user_id": 2,
    "survey_id": 1,
    "lang_id": "en-US",
    "title": "Neutral",
    "sort_number": 3,
    "created_at": "2024-07-15 12:15:00",
    "updated_at": "2024-07-15 12:15:00",
    "deleted_at": null
  }
}
```

## \[Adm.] Update

Update an existing `SurveyAnswerOption` by `id`.

**Definition**

<mark style="color:blue;">`PUT`</mark> `/api/administration/surveys/{survey}/answer-options/{id}`

**Request Keys**

| Key           | Type    | Description                                                                                                                 |
| ------------- | ------- | --------------------------------------------------------------------------------------------------------------------------- |
| `title`       | string  | The answer option text.                                                                                                     |
| `sort_number` | integer | The index of the `SurveyAnswerOption` related to the [Survey](https://docs.api.intratool.de/api-reference/surveys/surveys). |

**Example Request**

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

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('PUT', '/api/administration/surveys/1/answer-options/3', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'sort_number' => 1
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 3,
    "user_id": 2,
    "survey_id": 1,
    "lang_id": "en-US",
    "title": "Neutral",
    "sort_number": 1,
    "created_at": "2024-07-15 12:15:00",
    "updated_at": "2024-07-15 12:30:00",
    "deleted_at": null
  }
}
```

## Delete

Delete an existing `SurveyAnswerOption` by `id`.

**Definition**

<mark style="color:red;">`DELETE`</mark> `/api/administration/surveys/{survey}/answer-options/{id}`

**Example Request**

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

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('DELETE', '/api/administration/surveys/1/answer-options/3', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": null
}
```
