Set Question Display Logic and Skip Logic Using the v5 API

The v5 Alchemer API allows you to configure both Display Logic and Skip Logic for survey questions with the surveyquestion methods for GET, PUT, and POST (get, create, update). 

https://api.alchemer.com/v5/survey/123456/surveyquestion/1

https://api.alchemer.com/v5/survey/123456/surveypage/1/surveyquestion?_method=PUT

https://api.alchemer.com/v5/survey/123456/surveyquestion/1?_method=POST

These options correspond to the options on the 'Logic' tab in the question builder.

Set Question Display Options with the v5 API


Save Question Data if Hidden After Initial Display

  • Parameter: properties[save_logic_data]
  • Implementation: Pass the save_logic_data parameter.

Hide Question After Answering

  • Parameter: properties[hide_after_response]
  • Implementation: Pass the hide_after_response parameter.
  • To Disable: Pass an empty string.

Hide Question by Default (Used with Custom Scripting)

  • Parameter:properties[hidden]
  • Type: Boolean: true/false

Show Question Only to Admin Users

  • Parameter:properties[admin_question]
  • Type: Boolean: true/false

Disable Question

  • Parameter:properties[disabled]
  • Type: Boolean: true/false

Alias (Short Name for the Question)

  • Parameter:shortname
  • Type: String

SPSS Variable Name

  • Parameter:varname
  • Type: String

Randomization & Placement Properties

  • Always Include Question When Showing a Random Selection

    • Parameter:properties[randomizer_ignore]
    • Type: Boolean: true/false

  • Fix Question Position When Shuffling is Enabled
    • Parameter:properties[fixed_placement]
    • Type: Boolean: true/false


Set question skip logic with the v5 API

These options correspond to the logic rules in the 'Logic' tab in the question builder.

Logic Structure

The API uses a structured JSON format to define question display conditions in the show_rules  parameter.

{
  "show_rules": {
    "atom": {
      "type": 3,
      "value": 2
    },
    "operator": 20,
    "atom2": {
      "type": 17,
      "value": null
    }
  }
}

Components:

  • atom: The primary condition entity id.  This is usually a question or respondent metadata.  This corresponds to the 'select a condition' dropdown in the builder interface.

  • operator: The logical condition id (e.g., 20 for ANSWERED).  Different question types or conditions have different operators.  See below for details.

  • atom2: The secondary condition entity or expected value.  This is a complex type and will vary depending on the question type and operator.  See below for details.

Tip: 

The quickest way to get a sense of the logic structure is to build the desired logic using the web interface then get the question details using the API.  The response includes the full show_rules.


Note:

The question details API response also includes the show_rules id and same_page_skus.  These are not required to be supplied when setting the show_rules with the API.

An Atom corresponds to the minimal logic unit where:

  • Type is 3 is the QUESTION condition type.  Other available condition types are:

List of Condition Types

Type ID Type Description
3 SGLogicAtom_TYPE_QUESTION
6 SGLogicAtom_TYPE_CURRENTDATE
21 SGLogicAtom_TYPE_MOBILE
5 SGLogicAtom_TYPE_IP
8 SGLogicAtom_TYPE_COUNTRY
9 SGLogicAtom_TYPE_REGION
19 SGLogicAtom_TYPE_POSTAL
10 SGLogicAtom_TYPE_CITY
4 SGLogicAtom_TYPE_URLVAR
36 SGLogicAtom_TYPE_SSOVAR
13 SGLogicAtom_TYPE_INVITEFIELD


The above table corresponds with the options available in the Alchemer UI: 

Every condition has a set of operators: 

Example 1: Basic Condition


The following example represents a condition in which the visibility of an element depends on specific criteria:

[
  'atom' => [
    'type' => 3,
    'value' => 2
  ],
  'operator' => 20,
  'atom2' => [
    'type' => 17,
    'value' => null
  ],
]
  • Atom (atom)

    • type: 3 (Question)

    • value: 2 (ID of the relevant question)

    • The value field represents the entity to which the condition applies. If the type is a question, the value must be the question's ID.

  • Operator (operator)

    • 20 (Represents the "ANSWERED" condition)

    • Each condition type has a corresponding set of valid operators, similar to the options available in the UI.

  • Second Atom (atom2)

    • type: 17 (QUESTION_OPTIONS)

    • value: null

    • Since the operator is ANSWERED, no specific value is needed. The condition is satisfied if the question has been answered.

Example 2: Multi-Condition

To specify particular answers for a question, the structure must be adjusted as follows:

[
    "atom": [
        "type": 3,
        "value": 2
    ],
    "operator": 12,
    "atom2": [
        "type": 17,
        "value": [
            "2-10003",
            "2-10004",
            "2-10005"
        ]
    ]
]
  • Atom (atom)

    • type: 3 (Question)

    • value: 2 (ID of the "Select One Day" question)

  • Operator (operator)

    • 12 (Represents the "IN_LIST" condition)

  • Second Atom (atom2)

    • type: 17 (QUESTION_OPTIONS)
    • value: ["2-10003", "2-10004", "2-10005"]
    • Each value consists of a question ID (2) and option IDs (10003, 10004, 10005). In the UI, these correspond to the options "Monday," "Tuesday," and "Wednesday."

Question-Specific Logic

For atom2 type, use the following:

  • If the question has predefined answer options:
    17 => SGLogicAtom_TYPE_QUESTION_OPTIONS

  • If the question allows free text input (e.g., text fields, common text-based responses):
    2 => SGLogicAtom_TYPE_VALUE

Prohibited Question Types

The following question types are not supported:

  • File Upload

  • Drag and Drop

  • Ranking Grid

  • Signature

  • Continuous Sum

  • Textbox List

  • Slider List

  • Video Sentiment

  • Audio Sentiment

  • Grouping (Open Card Sort)

  • Dropdown Menu Grid

  • Textbox Grid

  • Max Diff

  • Custom Table

Additionally, since the platform treats Actions and Text/Media elements as questions, they are also excluded from the Logic Builder.


Single-Select Questions

(Applies to: Radio Buttons, Radio Button Grid, Net Promoter Score, Rating (Likert Scale), Image (Select One), Dropdown Menu List, Grouping (Closed Card Sort), Quick Sort, Semantic Differential, User Data)

 3  => SGLogicAtom_TYPE_QUESTION => [
    12 => SGLogicUnit_LOGIC_IN_LIST,
    5  => SGLogicUnit_LOGIC_NOTEQUAL,
    20 => SGLogicUnit_LOGIC_ANSWERED,
    21 => SGLogicUnit_LOGIC_NOTANSWERED
  ] => [ 
    17 => SGLogicAtom_TYPE_QUESTION_OPTIONS
  ],

Multi-Select Questions

(Applies to: Checkboxes, Image (Multi-Select), Checkbox Grid, Conjoint (Choice-Based)

 3  => SGLogicAtom_TYPE_QUESTION => [
     4  => SGLogicUnit_LOGIC_EQUAL,
    22 => SGLogicUnit_LOGIC_NOT_EXACTLYEQUAL,
    12 => SGLogicUnit_LOGIC_IN_LIST,
    5  => SGLogicUnit_LOGIC_NOTEQUAL,
    20 => SGLogicUnit_LOGIC_ANSWERED,
    21 => SGLogicUnit_LOGIC_NOTANSWERED
  ] => [ 
    17 => SGLogicAtom_TYPE_QUESTION_OPTIONS
  ],

Text-Based Questions

(Applies to: Textbox, Essay/Long Answer)

Atom 2 type should be changed to SGLogicAtom_TYPE_VALUE 

 3  => SGLogicAtom_TYPE_QUESTION => [
     4  => SGLogicUnit_LOGIC_EQUAL,
    22 => SGLogicUnit_LOGIC_NOT_EXACTLYEQUAL,
    6  => SGLogicUnit_LOGIC_GT,
    7  => SGLogicUnit_LOGIC_GTE,
    8  => SGLogicUnit_LOGIC_LTE,
    9  => SGLogicUnit_LOGIC_LT,
    23 => SGLogicUnit_LOGIC_GTE_DATE,
    24 => SGLogicUnit_LOGIC_LTE_DATE,
    20 => SGLogicUnit_LOGIC_ANSWERED,
    21 => SGLogicUnit_LOGIC_NOTANSWERED,
    10 => SGLogicUnit_LOGIC_CONTAINSTR,
    14 => SGLogicUnit_LOGIC_REGEX,
    15 => SGLogicUnit_LOGIC_NOTREGEX,
    28 => SGLogicUnit_LOGIC_SENTIMENT_POS,
    30 => SGLogicUnit_LOGIC_SENTIMENT_NEU,
    29 => SGLogicUnit_LOGIC_SENTIMENT_NEG,
    31 => SGLogicUnit_LOGIC_SENTIMENT_GT,
    32 => SGLogicUnit_LOGIC_SENTIMENT_LT,
  ] => [ 
    2 => SGLogicAtom_TYPE_VALUE
  ],

Email, Date, Number, Percent

Atom 2 type should be changed to SGLogicAtom_TYPE_VALUE

 3  => SGLogicAtom_TYPE_QUESTION => [
    4  => SGLogicUnit_LOGIC_EQUAL,
    22 => SGLogicUnit_LOGIC_NOT_EXACTLYEQUAL,
    6  => SGLogicUnit_LOGIC_GT,
    7  => SGLogicUnit_LOGIC_GTE,
    8  => SGLogicUnit_LOGIC_LTE,
    9  => SGLogicUnit_LOGIC_LT,
    23 => SGLogicUnit_LOGIC_GTE_DATE,
    24 => SGLogicUnit_LOGIC_LTE_DATE,
    20 => SGLogicUnit_LOGIC_ANSWERED,
    21 => SGLogicUnit_LOGIC_NOTANSWERED,
    10 => SGLogicUnit_LOGIC_CONTAINSTR,
    14 => SGLogicUnit_LOGIC_REGEX,
    15 => SGLogicUnit_LOGIC_NOTREGEX
  ] => [ 
    2 => SGLogicAtom_TYPE_VALUE
  ],

Slider

 3  => SGLogicAtom_TYPE_QUESTION => [
     4  => SGLogicUnit_LOGIC_EQUAL,
    22 => SGLogicUnit_LOGIC_NOT_EXACTLYEQUAL,
    12 => SGLogicUnit_LOGIC_IN_LIST,
    5  => SGLogicUnit_LOGIC_NOTEQUAL,
    6  => SGLogicUnit_LOGIC_GT,
    7  => SGLogicUnit_LOGIC_GTE,
    8  => SGLogicUnit_LOGIC_LTE,
    9  => SGLogicUnit_LOGIC_LT,
    23 => SGLogicUnit_LOGIC_GTE_DATE,
    24 => SGLogicUnit_LOGIC_LTE_DATE,
    20 => SGLogicUnit_LOGIC_ANSWERED,
    21 => SGLogicUnit_LOGIC_NOTANSWERED,
    10 => SGLogicUnit_LOGIC_CONTAINSTR,
    14 => SGLogicUnit_LOGIC_REGEX,
    15 => SGLogicUnit_LOGIC_NOTREGEX
  ] => [ 
    17 => SGLogicAtom_TYPE_QUESTION_OPTIONS
  ],

Star Rating Grid

 3  => SGLogicAtom_TYPE_QUESTION => [
    4  => SGLogicUnit_LOGIC_EQUAL
    22 => SGLogicUnit_LOGIC_NOT_EXACTLYEQUAL
    12 => SGLogicUnit_LOGIC_IN_LIST,
    5  => SGLogicUnit_LOGIC_NOTEQUAL,
    23 => SGLogicUnit_LOGIC_GTE_DATE,
    24 => SGLogicUnit_LOGIC_LTE_DATE,
    20 => SGLogicUnit_LOGIC_ANSWERED,
    21 => SGLogicUnit_LOGIC_NOTANSWERED
  ] => [ 
    2 => SGLogicAtom_TYPE_VALUE
  ],

Image Heatmap, Text Highlighter, Cascading Dropdown

 3  => SGLogicAtom_TYPE_QUESTION => [
  20 => SGLogicUnit_LOGIC_ANSWERED,
  21 => SGLogicUnit_LOGIC_NOTANSWERED
  ] => [ 
    2 => SGLogicAtom_TYPE_VALUE
  ],



Basic Standard Market Research HR Professional Full Access Reporting
Free Individual Team & Enterprise
Feature Included In