> ## 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.

# Poll Posts

> Create poll posts that reference an existing Social+ poll.

Poll posts share an existing poll in a user or community feed. Create the poll first with the Poll Repository, then create a post that references the returned `pollId`.

<Warning>
  Create the poll before creating the post. See [Poll Creation Guidelines](/social-plus-sdk/core-concepts/content-handling/poll#create-a-poll) for poll creation examples.
</Warning>

<CardGroup cols={2}>
  <Card title="Poll Reference" icon="square-poll-vertical">
    A poll post points to a `pollId` returned by the poll creation flow.
  </Card>

  <Card title="Feed Delivery" icon="rss">
    Publish the poll into a user feed or community feed with optional text.
  </Card>
</CardGroup>

## Parameters

| Parameter    | Required | Description                                                   |
| ------------ | -------- | ------------------------------------------------------------- |
| `pollId`     | Yes      | ID of an existing poll created before post creation.          |
| `text`       | No       | Feed caption or prompt shown with the poll post.              |
| `targetType` | Yes      | Feed target, usually `community` or `user`.                   |
| `targetId`   | Yes      | Community ID or user ID for the target feed.                  |
| `metadata`   | No       | Custom metadata stored with the post where supported.         |
| `mentionees` | No       | User mention payload where supported by the platform builder. |

## Create a Poll Post

The examples below create a poll post in a community from an existing `pollId`.

<CodeGroup>
  ```swift iOS theme={null}
  func createPollPost(
      pollId: String,
      communityId: String
  ) async throws -> AmityPost {
      let postRepository = AmityPostRepository()
      let builder = AmityPollPostBuilder()
      builder.setPollId(pollId)
      builder.setText("Vote in this poll")

      return try await postRepository.createPollPost(
          builder,
          targetId: communityId,
          targetType: .community,
          metadata: nil,
          mentionees: nil
      )
  }
  ```

  ```kotlin Android theme={null}
  postRepository.createPollPost(
      targetType = AmityPost.TargetType.COMMUNITY,
      targetId = communityId,
      pollId = pollId,
      text = "Vote in this poll"
  )
      .subscribe({ post ->
          showSuccessMessage(post.getPostId())
      }, { error ->
          handleGeneralError(error)
      })
  ```

  ```typescript TypeScript theme={null}
  import { PostRepository } from "@amityco/ts-sdk";

  const { data: post } = await PostRepository.createPost({
    targetType: "community",
    targetId: communityId,
    dataType: "poll",
    data: {
      text: "Vote in this poll",
      pollId,
    },
  });
  ```

  ```dart Flutter theme={null}
  final post = await AmitySocialClient.newPostRepository()
      .createPost()
      .targetCommunity(communityId)
      .poll(pollId)
      .text('Vote in this poll')
      .post();
  ```
</CodeGroup>

## Notes

* The post creation call does not create the poll. It only attaches an existing poll by ID.
* Keep the poll question, answers, answer type, and close time in the poll creation flow.
* Use the post text for feed context or a short prompt; the poll object remains the source of truth for answer options and voting behavior.

## Related Topics

<CardGroup cols={3}>
  <Card title="Poll Creation" icon="square-poll-vertical" href="/social-plus-sdk/core-concepts/content-handling/poll#create-a-poll">
    Create the poll object before publishing a poll post.
  </Card>

  <Card title="Text Posts" icon="text" href="./text-post">
    Create a simple feed post without a poll attachment.
  </Card>

  <Card title="Posts Overview" icon="newspaper" href="../overview">
    Review post concepts, retrieval, and moderation flows.
  </Card>
</CardGroup>
