> ## Documentation Index
> Fetch the complete documentation index at: https://social-b97141fb-auto-generate-llmstxt.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Polls

> Create polls, collect votes, and manage poll lifecycle with the Social+ SDKs.

Polls are created first, then attached to poll posts when you want them to appear in a feed. The SDKs expose poll creation, voting, closing, and deletion APIs. TypeScript, iOS, and Android also expose an unvote API; the current Flutter public poll repository does not expose unvote.

## Platform Surface

| Platform   | Create                                               | Vote                          | Unvote                | Close                | Delete                |
| ---------- | ---------------------------------------------------- | ----------------------------- | --------------------- | -------------------- | --------------------- |
| TypeScript | `PollRepository.createPoll()`                        | `votePoll()`                  | `unvotePoll()`        | `closePoll()`        | `deletePoll()`        |
| iOS        | `AmityPollRepository.createPoll()`                   | `votePoll(withId:answerIds:)` | `unvotePoll(withId:)` | `closePoll(withId:)` | `deletePoll(withId:)` |
| Android    | `AmitySocialClient.newPollRepository().createPoll()` | `votePoll()`                  | `unvotePoll()`        | `closePoll()`        | `deletePoll()`        |
| Flutter    | `AmitySocialClient.newPollRepository().createPoll()` | `vote()`                      | Not exposed           | `closePoll()`        | `deletePoll()`        |

## Parameters

| Parameter                   | Required                | Description                                                                                                                           |
| --------------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `question`                  | Yes                     | Poll question text.                                                                                                                   |
| `answers`                   | Yes                     | Text or image answer options, depending on SDK and answer type.                                                                       |
| `answerType`                | No                      | Single-choice or multiple-choice poll. Defaults to single-choice where the SDK builder provides a default.                            |
| `closedIn` / close duration | No                      | Optional poll close duration. Mobile SDKs expose milliseconds or `Duration`; TypeScript passes `closedIn` through as a numeric field. |
| `pollId`                    | Required after creation | ID returned by poll creation and used for voting, closing, deleting, and poll posts.                                                  |
| `answerIds`                 | Required for voting     | Answer IDs selected by the user.                                                                                                      |

## Create A Poll

Create the poll first and keep the returned `pollId` if you need to create a poll post.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { PollRepository } from "@amityco/ts-sdk";

  const { data: poll } = await PollRepository.createPoll({
    question: "Which feature should we build next?",
    answerType: "single",
    answers: [
      { dataType: "text", data: "Bookmarks" },
      { dataType: "text", data: "Pinned comments" },
    ],
  });

  const createdPollId = poll.pollId;
  ```

  ```swift iOS theme={null}
  let pollRepository = AmityPollRepository()
  let options = AmityPollCreateOptions()
  options.setQuestion("Which feature should we build next?")
  options.setAnswerType(.single)
  options.setAnswer("Bookmarks")
  options.setAnswer("Pinned comments")

  let createdPollId = try await pollRepository.createPoll(options)
  ```

  ```kotlin Android theme={null}
  import com.amity.socialcloud.sdk.model.social.poll.AmityPollAnswer

  val pollRepository = AmitySocialClient.newPollRepository()

  pollRepository.createPoll("Which feature should we build next?")
      .answers(
          listOf(
              AmityPollAnswer.Data.TEXT("Bookmarks"),
              AmityPollAnswer.Data.TEXT("Pinned comments")
          )
      )
      .answerType(AmityPoll.AnswerType.SINGLE)
      .build()
      .create()
      .subscribe(
          { createdPollId -> showSuccessMessage(createdPollId) },
          { error -> handleGeneralError(error) }
      )
  ```

  ```dart Flutter theme={null}
  final poll = await AmitySocialClient.newPollRepository()
      .createPoll(question: 'Which feature should we build next?')
      .answers(answers: [
        AmityPollAnswer.text('Bookmarks'),
        AmityPollAnswer.text('Pinned comments'),
      ])
      .answerType(answerType: AmityPollAnswerType.SINGLE)
      .create();

  final createdPollId = poll.pollId;
  ```
</CodeGroup>

## Vote And Manage A Poll

Use answer IDs from the poll object when voting. Closing and deletion use the poll ID.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { PollRepository } from "@amityco/ts-sdk";

  const answerIds = ["answer-id"];

  const { data: votedPoll } = await PollRepository.votePoll(pollId, answerIds);
  await PollRepository.unvotePoll(pollId);

  const { data: closedPoll } = await PollRepository.closePoll(pollId);
  const isDeleted = await PollRepository.deletePoll(pollId);
  ```

  ```swift iOS theme={null}
  let pollRepository = AmityPollRepository()
  let answerIds = ["answer-id"]

  try await pollRepository.votePoll(withId: pollId, answerIds: answerIds)
  try await pollRepository.unvotePoll(withId: pollId)
  try await pollRepository.closePoll(withId: pollId)
  try await pollRepository.deletePoll(withId: pollId)
  ```

  ```kotlin Android theme={null}
  val pollRepository = AmitySocialClient.newPollRepository()
  val answerIds = listOf("answer-id")

  pollRepository.votePoll(pollId, answerIds)
      .subscribe(
          { showSuccessMessage("Vote submitted") },
          { error -> handleGeneralError(error) }
      )

  pollRepository.unvotePoll(pollId)
      .subscribe(
          { showSuccessMessage("Vote removed") },
          { error -> handleGeneralError(error) }
      )

  pollRepository.closePoll(pollId)
      .subscribe(
          { showSuccessMessage("Poll closed") },
          { error -> handleGeneralError(error) }
      )

  pollRepository.deletePoll(pollId)
      .subscribe(
          { showSuccessMessage("Poll deleted") },
          { error -> handleGeneralError(error) }
      )
  ```

  ```dart Flutter theme={null}
  final pollRepository = AmitySocialClient.newPollRepository();
  final answerIds = ['answer-id'];

  await pollRepository.vote(pollId: pollId, answerIds: answerIds);
  final closedPoll = await pollRepository.closePoll(pollId: pollId);
  final isDeleted = await pollRepository.deletePoll(pollId: pollId);
  ```
</CodeGroup>

## Notes

* Create a poll post separately after poll creation. Poll creation returns a poll ID; poll-post creation attaches that ID to feed content.
* Use `answerType` values that match each SDK: TypeScript uses `single` or `multiple`, iOS uses `.single` or `.multiple`, Android uses `AmityPoll.AnswerType`, and Flutter uses `AmityPollAnswerType`.
* Flutter currently exposes `vote`, `closePoll`, and `deletePoll`, but not an unvote method on the public poll repository.
* Deletion and close behavior depends on server-side permissions for the current user.

## Related Topics

<CardGroup cols={3}>
  <Card title="Poll Posts" icon="square-poll-vertical" href="/social-plus-sdk/social/content-management/posts/creation/poll-post">
    Attach an existing poll to a feed post
  </Card>

  <Card title="Text Posts" icon="pen-line" href="/social-plus-sdk/social/content-management/posts/creation/text-post">
    Create regular text posts for the same feed targets
  </Card>

  <Card title="Post Retrieval" icon="search" href="/social-plus-sdk/social/content-management/posts/retrieval/get-post">
    Fetch posts that contain poll data
  </Card>
</CardGroup>
