chatformdocs
Blocks

Number

A quantity: how many guests, how many seats, a budget.

Numbernumber

A quantity: how many guests, how many seats, a budget.

How it gets answered — extracted from free text by the agent, then re-validated.

Configuration

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

number configuration
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "buttonLabel": {
      "type": "string",
      "maxLength": 60
    },
    "type": {
      "type": "string",
      "const": "number"
    },
    "unique": {
      "default": false,
      "type": "boolean"
    },
    "min": {
      "type": "number"
    },
    "max": {
      "type": "number"
    },
    "integerOnly": {
      "default": false,
      "type": "boolean"
    },
    "currency": {
      "type": "string",
      "minLength": 3,
      "maxLength": 3
    }
  },
  "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: min, max, integerOnly=true, currency=<3-letter code> when it is money; unique=true to refuse a value another respondent already gave, such as a team name, a username or a seat number.

What you receive

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

PublicBlock
{
  "id": "blk_num00001",
  "ref": "q_team",
  "type": "number",
  "title": "Team size?",
  "required": true,
  "imageKey": null,
  "media": null,
  "min": 1,
  "max": 500,
  "integerOnly": true
}

What you send

A number, within the block's bounds.

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_team", "value": 12}'

What gets stored

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

You sendStored
1212
"12"12numeric strings are coerced

Errors

CodeWhenMessage
requiredan empty answer on a required blockThis question needs an answer.
type"twelve"Please enter a number.
not_integer1.5Please enter a whole number.
too_small0Please enter a number ≥ 1.
too_large501Please enter a number ≤ 500.
duplicateunique is on and another response already gave this answerSomeone has already used that — please try a different one.

On this page