> For the complete documentation index, see [llms.txt](https://docs.pollsapi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pollsapi.com/api/create-poll.md).

# Create poll

## Fields Information

### **Poll**

| Key                     | Type     | Description                                                         |
| ----------------------- | -------- | ------------------------------------------------------------------- |
| **question** `required` | `string` | The question/title of the Poll                                      |
| **identifier**          | `string` | Can be used to pass in custom identifier, eg - user id, email, etc. |
| **data**                | `object` | A flexible data field to store any meta data with each option       |

### **Option**

**Minimum 2 Options are required in a poll** (Just making the obvious known :sweat\_smile: )

| Key                 | Type     | Description                                                   |
| ------------------- | -------- | ------------------------------------------------------------- |
| **text** `required` | `string` | String to store the option's text                             |
| **data**            | `object` | A flexible data field to store any meta data with each option |

## Creating a Poll

<mark style="color:green;">`POST`</mark> `https://api.pollsapi.com/v1/create/poll`

This endpoint allows you to get free cakes.

#### Headers

| Name         | Type   | Description              |
| ------------ | ------ | ------------------------ |
| Content-Type | string | application/json         |
| api-key      | string | API Key for your account |

#### Request Body

| Name       | Type   | Description                                                                                  |
| ---------- | ------ | -------------------------------------------------------------------------------------------- |
| identifier | string | Can be used to store a custom identifier                                                     |
| data       | object | A flexible data field to store custom metadata                                               |
| question   | string | The question/title of the poll you are creating                                              |
| options    | array  | List of options the poll should have(Min. 2). Please check below for the structure of Option |

{% tabs %}
{% tab title="200 Poll Created" %}

```javascript
{
  "status": "success",
  "statusCode": 200,
  "data": {
    "identifier": null,
    "question": "Do you like polls?",
    "data": {},
    "created_at": "2020-10-24T02:28:46.391Z",
    "updated_at": "2020-10-24T02:28:46.391Z",
    "id": "5f93915e7e044c74074f072e",
    "entity": "Poll",
    "options": [
      {
        "text": "Yes",
        "votes_count": 0,
        "data": {},
        "poll_id": "5f93915e7e044c74074f072e",
        "created_at": "2020-10-24T02:28:46.422Z",
        "updated_at": "2020-10-24T02:28:46.422Z",
        "id": "5f93915e7e044c74074f072f",
        "entity": "Option"
      },
      {
        "text": "No",
        "votes_count": 0,
        "data": {},
        "poll_id": "5f93915e7e044c74074f072e",
        "created_at": "2020-10-24T02:28:46.422Z",
        "updated_at": "2020-10-24T02:28:46.422Z",
        "id": "5f93915e7e044c74074f0730",
        "entity": "Option"
      }
    ]
  }
}
```

{% endtab %}
{% endtabs %}

### Example cURL request

```bash
curl -X POST \
  'https://api.pollsapi.com/v1/create/poll' \
  -H 'content-type: application/json' \
  -H "api-key: $API_KEY" \
  -d '
{
  "question": "Do you like polls?",
  "options": [
    {
      "text": "Yes"
    },
    {
      "text": "No"
    }
  ]
}
'
```

## Request Body

```javascript
{
    "question": "Does this doc help?",
    "identifier": "custom_identifier",
    "data": {
        "custom": "Poll Data"
    }
    "options": [
        {
            "text": "Option Text",
            "data": {
                "custom": "data"
            }
        },
        {
            "text": "Option Text2",
            "data": {
                "custom": "data"
            }
        }
    ]
}
```

##
