Skip to main content

Configuring Polls with Community Configurations

Overview

The LikeMinds platform enables communities to configure poll behavior programmatically using the Community Configuration APIs. This guide outlines how to define default poll settings, manage overrides, and leverage API options for a flexible and robust polling experience.


Prerequisites

Before configuring polls using community settings, ensure you have:

  • Access to a community with poll functionality enabled
  • Admin or Community Manager privileges to modify configurations

Authentication

To update poll settings, you must authenticate as an Admin or Community Manager.

Authentication Steps

Call the POST sdk/initiate API:

curl --location 'https://auth.likeminds.community/sdk/initiate'  \
--header 'x-api-key: LM_API_KEY' \
--data '{
"user_name": "ADMIN_NAME",
"user_unique_id": "ADMIN_UUID"
}'

Extract the access_token from the response for use in API calls.


Configuring Polls

API Endpoints

  • Get Community Configurations: GET /community/configurations

    • Purpose: Fetches the community configurations, including poll settings.
    • Request Parameters:
      • configuration_types: String (set to "chat_poll" to retrieve poll configurations).
    • Response:
      • Returns a JSON object with type, description, and value (the poll configuration object).
  • Update Community Configurations: PATCH /community/configurations

    • Purpose: Updates the community configurations for polls.
    • Request Parameters:
      • type: String (set to "chat_poll").
      • value: JSON object containing the poll configuration settings (e.g., allow_override, poll_type, etc.).
    • Behavior:
      • Updates the configurations with the provided values.
      • Validates constraints (e.g., no_poll_expiry cannot be true for deferred polls).
  • Create a Poll: POST /conversation

    • Purpose: Creates a new poll conversation.
    • Request Parameters (relevant to poll configurations):
      • state: Set to 10 to denote a poll conversation.
      • poll_type: Integer
      • no_poll_expiry: Boolean (default: false).
      • allow_vote_change: Boolean (default: false for instant polls, true otherwise).
      • multiple_select_state: Integer
      • multiple_select_no: Integer (number of options for multiple selection).
      • is_anonymous: Boolean (default: false).
      • allow_add_option: Boolean (default: false).
      • expiry_time: Epoch time (required unless no_poll_expiry is true).
      • polls: Array of objects with { "text": "<option_text>" }.
    • Behavior:
      • Fetches community configurations for chat_poll type.
      • If allow_override is false, uses configuration values instead of API parameters.
      • Validates constraints (e.g., no_poll_expiry cannot be true for deferred polls).

These endpoints allow fetching and updating default poll behaviors and creating poll conversations accordingly.


Poll Configuration Fields

FieldTypeDefaultDescription
allow_overrideBooleantrueAllows API-provided parameters to override community configuration
poll_typeString"instant""instant", "deferred", or "open"
no_poll_expiryBooleanfalseIf true, the poll does not expire
allow_vote_changeBooleantrue/falseAllows users to change votes (false for instant polls by default)
multiple_select_stateString"exactly""exactly", "at_max", or "at_least"
multiple_select_noInteger1Number of choices users must/can select
is_anonymousBooleanfalseHides voter identity if true
allow_add_optionBooleanfalseAllows users to add new poll options

To update configurations:

curl --location --request PATCH 'https://auth.likeminds.community/community/configurations'  \
--header 'Authorization: ADMIN_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"type": "chat_poll",
"value": {
"poll_type": "deferred",
"allow_override": true,
...
}
}'

Creating a Poll

API Endpoint

  • POST /conversation
  • Authentication: Bearer Token (Admin/CM token)

Request Body Example

{
"state": 10,
"poll_type": 1,
"expiry_time": 1712179200,
"multiple_select_state": 1,
"multiple_select_no": 2,
"is_anonymous": true,
"allow_add_option": true,
"polls": [{ "text": "Option A" }, { "text": "Option B" }]
}

Example Use Cases

Instant Poll with Strict Voting

  • Use Case:
    • Only one option can be selected
    • No vote changes allowed
    • Results visible immediately
  • Set Community Configuration
PATCH /community/configurations
{
"type": "chat_poll",
"value": {
"allow_override": false,
"poll_type": "instant",
"no_poll_expiry": false,
"allow_vote_change": false,
"multiple_select_state": "exactly",
"multiple_select_no": 1,
"is_anonymous": false,
"allow_add_option": false
}
}
  • API Call for Create Poll:
POST /conversation
{
"state": 10,
"expiry_time": 1711584000, // March 28, 2025, 00:00 UTC
"polls": [{"text": "Do you like the new feature?"}, {"text": "No, needs improvement"}]
}

Deferred Poll for Event Planning

  • Use Case:
    • Multiple options allowed
    • Anonymous voting
    • Results shown after expiry
  • Set Community Configuration
PATCH /community/configurations
{
"type": "chat_poll",
"value": {
"allow_override": true,
"poll_type": "deferred",
"no_poll_expiry": false,
"allow_vote_change": true,
"multiple_select_state": "at_max",
"multiple_select_no": 2,
"is_anonymous": true,
"allow_add_option": true
}
}
  • API Call for Create Poll:
POST /conversation
{
"state": 10,
"poll_type": 1,
"expiry_time": 1712179200, // April 4, 2025, 00:00 UTC
"multiple_select_state": 1,
"multiple_select_no": 2,
"is_anonymous": true,
"allow_add_option": true,
"polls": [ {"text": "April 10"}, {"text": "April 17"} ]
}

Open Poll for Ongoing Suggestions

  • Use Case:
    • Always-visible results
    • Users can change votes
    • Flexible participation
  • Set Community Configuration
PATCH /community/configurations
{
"type": "chat_poll",
"value": {
"allow_override": false,
"poll_type": "open",
"no_poll_expiry": true,
"allow_vote_change": true,
"multiple_select_state": "at_least",
"multiple_select_no": 1,
"is_anonymous": false,
"allow_add_option": false
}
}
  • API Call for Create Poll:
POST /conversation
{
"state": 10,
"poll_type": 1,
"expiry_time": 1712179200, // April 4, 2025, 00:00 UTC
"polls": [{"text": "Project Alpha"}, {"text": "Project Beta"}]
}

Deferred Poll with Collaborative Options

  • Use Case:
    • Allows adding options
    • Anonymous or visible voting
    • Results after poll expiry
  • Set Community Configuration
PATCH /community/configurations
{
"type": "chat_poll",
"value": {
"allow_override": true,
"poll_type": "deferred",
"no_poll_expiry": false,
"allow_vote_change": false,
"multiple_select_state": "exactly",
"multiple_select_no": 1,
"is_anonymous": false,
"allow_add_option": true
}
}
  • API Call for Create Poll:
POST /conversation
{
"state": 10,
"poll_type": 1,
"expiry_time": 1711843200, // March 31, 2025, 00:00 UTC
"multiple_select_state": 0,
"multiple_select_no": 1,
"is_anonymous": false,
"allow_add_option": true,
"polls": [ {"text": "Action"}, {"text": "Comedy"} ]
}

Best Practices

  • Consistency: Keep poll settings aligned with community engagement goals.
  • User Experience: Clearly communicate poll behavior to users.
  • Constraints: Avoid configurations that violate API rules (e.g., no_poll_expiry with deferred polls).
  • Testing: Always validate in a staging environment before live deployment.