chatformdocs
Blocks

Opinion scale

Agree/disagree on a numbered scale.

Scaleopinion_scale

Agree/disagree on a numbered scale.

How it gets answered — matched exactly — never sent to a model.

Configuration

Fields specific to opinion_scale. The fields every block has — id, ref, title, required, visibility, media, agentHints, prefillParam, identityField — are documented once.

opinion_scale configuration
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "buttonLabel": {
      "type": "string",
      "maxLength": 60
    },
    "type": {
      "type": "string",
      "const": "opinion_scale"
    },
    "steps": {
      "default": 10,
      "type": "integer",
      "minimum": 2,
      "maximum": 11
    },
    "startAt": {
      "default": 1,
      "anyOf": [
        {
          "type": "number",
          "const": 0
        },
        {
          "type": "number",
          "const": 1
        }
      ]
    },
    "labelLow": {
      "type": "string",
      "maxLength": 100
    },
    "labelHigh": {
      "type": "string",
      "maxLength": 100
    }
  },
  "required": [
    "id",
    "ref",
    "title",
    "type"
  ],
  "$defs": {
    "__schema0": {
      "type": "object",
      "properties": {
        "op": {
          "type": "string",
          "enum": [
            "and",
            "or"
          ]
        },
        "conditions": {
          "default": [],
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "left": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "ref"
                      },
                      "ref": {
                        "type": "string",
                        "pattern": "^[a-z][a-z0-9_]{1,40}$"
                      }
                    },
                    "required": [
                      "kind",
                      "ref"
                    ]
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "variable"
                      },
                      "name": {
                        "type": "string",
                        "pattern": "^[a-z][a-z0-9_]{0,40}$"
                      }
                    },
                    "required": [
                      "kind",
                      "name"
                    ]
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "hidden"
                      },
                      "name": {
                        "type": "string",
                        "pattern": "^[a-zA-Z_][a-zA-Z0-9_.-]{0,60}$"
                      }
                    },
                    "required": [
                      "kind",
                      "name"
                    ]
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "literal"
                      }
                    },
                    "required": [
                      "kind"
                    ]
                  }
                ]
              },
              "op": {
                "type": "string",
                "enum": [
                  "eq",
                  "neq",
                  "gt",
                  "gte",
                  "lt",
                  "lte",
                  "contains",
                  "not_contains",
                  "starts_with",
                  "ends_with",
                  "matches_regex",
                  "is_empty",
                  "is_not_empty",
                  "is_checked",
                  "is_not_checked",
                  "includes",
                  "not_includes",
                  "ranked_above",
                  "ranked_below"
                ]
              },
              "value": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "number"
                  },
                  {
                    "type": "boolean"
                  },
                  {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                ]
              }
            },
            "required": [
              "left",
              "op"
            ]
          }
        },
        "groups": {
          "default": [],
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema0"
          }
        }
      },
      "required": [
        "op"
      ]
    }
  }
}

In a generated draft these arrive as config pairs: scale sets the number of steps.

What you receive

GET /v1/forms/{id} and every "next question" projects blocks through toPublicBlock. For the example above:

PublicBlock
{
  "id": "blk_opin0001",
  "ref": "q_agreement",
  "type": "opinion_scale",
  "title": "It was easy to use",
  "required": true,
  "imageKey": null,
  "media": null,
  "steps": 5,
  "startAt": 1,
  "labels": {}
}

What you send

An integer within the block's steps, offset by startAt.

type Answer = number;
curl -X POST https://api.chatform.in/v1/responses/{RESPONSE_ID}/answers \
  -H "x-api-key: $CHATFORM_SECRET_KEY" \
  -H "content-type: application/json" \
  -d '{"ref": "q_agreement", "value": 3}'

What gets stored

The value is normalised before it is saved, so what you read back is not always what you sent.

You sendStored
33

Errors

CodeWhenMessage
requiredan empty answer on a required blockThis question needs an answer.
type—
out_of_range0Please pick a number between 1 and 5.

On this page