> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# CastVote

# Package: richContent

# Namespace: RicosPolls

# Method link: https://dev.wix.com/docs/api-reference/assets/rich-content/polls-v1/cast-vote.md

## Permission Scopes:
Manage Ricos Polls: SCOPE.DC-RICOS.MANAGE-POLLS

## Introduction

Casts the caller's vote for a poll option.

Site visitors, site members and Wix users can call this method, subject to `settings.votingAccess`. Wix users vote with their own identity, and their votes aren't counted as anonymous.

Unless `settings.multipleVotes` is `true`, a vote for another option replaces the caller's previous vote. Casting a vote that the caller already cast doesn't change anything.

Returns the caller's votes in `currentVoterOptionIds` and the updated `results`. `results` is included only when the poll's settings allow the caller to see them. See `settings.resultsVisibility`.

---

## REST API

### Schema

```
 Method: castVote
 Description: Casts the caller's vote for a poll option.  Site visitors, site members and Wix users can call this method, subject to `settings.votingAccess`. Wix users vote with their own identity, and their votes aren't counted as anonymous.  Unless `settings.multipleVotes` is `true`, a vote for another option replaces the caller's previous vote. Casting a vote that the caller already cast doesn't change anything.  Returns the caller's votes in `currentVoterOptionIds` and the updated `results`. `results` is included only when the poll's settings allow the caller to see them. See `settings.resultsVisibility`.
 URL: https://www.wixapis.com/ricos/v1/polls/{pollId}/cast-vote
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  optionId
 Method parameters: 
   param name: optionId | type: optionId | description: GUID of the option to vote for. | required: true | validation: format GUID
 Return type: CastVoteResponse
  - name: results | type: PollResults | description: Voting results after the change. Returned only when the poll's settings allow the caller to see them. See `settings.resultsVisibility`.  
     - name: voteCount | type: integer | description: Total number of votes cast for all options. This is the number of votes, not voters: when `settings.multipleVotes` is `true`, a voter who chose several options is counted once per option.  Not returned when `settings.showVoteCounts` is `false`.  | validation: minimum 0, format int32
     - name: anonymousVoteCount | type: integer | description: Number of votes cast by site visitors who weren't logged in. Included in `voteCount`.  Not returned when `settings.showVoteCounts` is `false`.  | validation: minimum 0, format int32
     - name: optionResults | type: array<PollOptionResults> | description: Results for each option.  | validation: maxItems 50
        - name: optionId | type: string | description: Option GUID.  | validation: format GUID
        - name: voteCount | type: integer | description: Number of votes for the option.  Not returned when `settings.showVoteCounts` is `false`.  | validation: minimum 0, format int32
        - name: anonymousVoteCount | type: integer | description: Number of votes for the option cast by site visitors who weren't logged in. Included in `voteCount`.  Not returned when `settings.showVoteCounts` is `false`.  | validation: minimum 0, format int32
        - name: percentage | type: integer | description: Percentage of `results.voteCount` cast for the option, rounded to the nearest integer. Because of rounding, and because a voter can choose several options when `settings.multipleVotes` is `true`, the percentages of all options don't always add up to 100.  Returned even when `settings.showVoteCounts` is `false`, so that relative results can be displayed without counts.  | validation: minimum 0, maximum 100, format int32
        - name: latestVoters | type: array<IdentificationData> | description: Identities of up to 5 site members or Wix users who voted for the option most recently. To retrieve all voters, call List Voters. To get member names and photos, call Query Members.  Not returned when `settings.showVoters` or `settings.showVoteCounts` is `false`.  | validation: maxItems 5
           - ONE-OF: 
              - name: anonymousVisitorId | type: string | description: GUID of a site visitor who isn't logged in.  | validation: format GUID
              - name: memberId | type: string | description: GUID of a site member.  | validation: format GUID
              - name: wixUserId | type: string | description: GUID of a Wix user, such as the site owner or a contributor.  | validation: format GUID
              - name: appId | type: string | description: GUID of an app.  | validation: format GUID
  - name: currentVoterOptionIds | type: array<string> | description: IDs of the options the caller voted for after the change. Empty if the caller has no votes.  | validation: maxItems 50, format GUID

 Possible Errors:
   HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code: MEMBERS_ONLY_VOTING | Description: Site visitors who aren't logged in can't vote in this poll. Log in as a site member to vote.
   HTTP Code: 404 | Status Code: NOT_FOUND | Application Code: POLL_OPTION_NOT_FOUND | Description: Couldn't find the poll option.


```

### Examples

### Cast Vote
Casts the caller's vote for the "Performance tuning" option. The response includes `results` because the poll's settings allow the caller to see them.

```curl
curl -X POST \
  'https://www.wixapis.com/ricos/v1/polls/bee2255e-17c6-47a2-89a9-718e3317befb/cast-vote' \
  -H 'Authorization: <AUTH>' \
  -H 'Content-Type: application/json' \
  --data-binary '{
    "optionId": "d3ed0db9-62c9-4a4e-8af3-33c556c5039c"
  }'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.richContent.ricosPolls.castVote(pollId, optionId)
 Description: Casts the caller's vote for a poll option.  Site visitors, site members and Wix users can call this method, subject to `settings.votingAccess`. Wix users vote with their own identity, and their votes aren't counted as anonymous.  Unless `settings.multipleVotes` is `true`, a vote for another option replaces the caller's previous vote. Casting a vote that the caller already cast doesn't change anything.  Returns the caller's votes in `currentVoterOptionIds` and the updated `results`. `results` is included only when the poll's settings allow the caller to see them. See `settings.resultsVisibility`.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  pollId, optionId
 Method parameters: 
   param name: pollId | type: string | description: GUID of the poll to vote in. | required: true | validation: format GUID
   param name: optionId | type: string | description: GUID of the option to vote for. | required: true | validation: format GUID
 Return type: PROMISE<CastVoteResponse>
  - name: results | type: PollResults | description: Voting results after the change. Returned only when the poll's settings allow the caller to see them. See `settings.resultsVisibility`.  
     - name: voteCount | type: integer | description: Total number of votes cast for all options. This is the number of votes, not voters: when `settings.multipleVotes` is `true`, a voter who chose several options is counted once per option.  Not returned when `settings.showVoteCounts` is `false`.  | validation: minimum 0, format int32
     - name: anonymousVoteCount | type: integer | description: Number of votes cast by site visitors who weren't logged in. Included in `voteCount`.  Not returned when `settings.showVoteCounts` is `false`.  | validation: minimum 0, format int32
     - name: optionResults | type: array<PollOptionResults> | description: Results for each option.  | validation: maxItems 50
        - name: optionId | type: string | description: Option GUID.  | validation: format GUID
        - name: voteCount | type: integer | description: Number of votes for the option.  Not returned when `settings.showVoteCounts` is `false`.  | validation: minimum 0, format int32
        - name: anonymousVoteCount | type: integer | description: Number of votes for the option cast by site visitors who weren't logged in. Included in `voteCount`.  Not returned when `settings.showVoteCounts` is `false`.  | validation: minimum 0, format int32
        - name: percentage | type: integer | description: Percentage of `results.voteCount` cast for the option, rounded to the nearest integer. Because of rounding, and because a voter can choose several options when `settings.multipleVotes` is `true`, the percentages of all options don't always add up to 100.  Returned even when `settings.showVoteCounts` is `false`, so that relative results can be displayed without counts.  | validation: minimum 0, maximum 100, format int32
        - name: latestVoters | type: array<IdentificationData> | description: Identities of up to 5 site members or Wix users who voted for the option most recently. To retrieve all voters, call List Voters. To get member names and photos, call Query Members.  Not returned when `settings.showVoters` or `settings.showVoteCounts` is `false`.  | validation: maxItems 5
           - ONE-OF: 
              - name: anonymousVisitorId | type: string | description: GUID of a site visitor who isn't logged in.  | validation: format GUID
              - name: memberId | type: string | description: GUID of a site member.  | validation: format GUID
              - name: wixUserId | type: string | description: GUID of a Wix user, such as the site owner or a contributor.  | validation: format GUID
              - name: appId | type: string | description: GUID of an app.  | validation: format GUID
  - name: currentVoterOptionIds | type: array<string> | description: IDs of the options the caller voted for after the change. Empty if the caller has no votes.  | validation: maxItems 50, format GUID

 Possible Errors:
   HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code: MEMBERS_ONLY_VOTING | Description: Site visitors who aren't logged in can't vote in this poll. Log in as a site member to vote.
   HTTP Code: 404 | Status Code: NOT_FOUND | Application Code: POLL_OPTION_NOT_FOUND | Description: Couldn't find the poll option.


```

### Examples

### Cast a vote
Casts the caller's vote for the "Performance tuning" option. The response includes the results because the poll's settings allow the caller to see them.

```javascript
import { ricosPolls } from "@wix/rich-content";

async function castVote() {
  const response = await ricosPolls.castVote(
    "bee2255e-17c6-47a2-89a9-718e3317befb",
    "d3ed0db9-62c9-4a4e-8af3-33c556c5039c",
  );
}

/* Promise resolves to:
 * {
 *   "results": {
 *     "voteCount": 4,
 *     "anonymousVoteCount": 1,
 *     "optionResults": [
 *       {
 *         "optionId": "d3ed0db9-62c9-4a4e-8af3-33c556c5039c",
 *         "voteCount": 3,
 *         "anonymousVoteCount": 1,
 *         "percentage": 75,
 *         "latestVoters": [{ "memberId": "5c1a7f0e-3b52-4d1c-9a6e-2f8d4b7e1c93" }, { "memberId": "a7e3d9b2-6c41-4f58-8b0d-91e5c2f3a604" }]
 *       },
 *       {
 *         "optionId": "b36ac043-287c-4085-8713-d2118ed3c115",
 *         "voteCount": 1,
 *         "anonymousVoteCount": 0,
 *         "percentage": 25,
 *         "latestVoters": [{ "memberId": "7a5c1f2e-3b4d-4e6f-8a9b-0c1d2e3f4a5b" }]
 *       }
 *     ]
 *   },
 *   "currentVoterOptionIds": ["d3ed0db9-62c9-4a4e-8af3-33c556c5039c"]
 * }
 */

```

### castVote (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { ricosPolls } from '@wix/rich-content';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { ricosPolls },
  // Include the auth strategy and host as relevant
});


async function castVote(pollId,optionId) {
  const response = await myWixClient.ricosPolls.castVote(pollId,optionId);
};
```

---