Blocks
Ranking
Drag a list into order of preference. `options` are the things being ranked.
Choice
rankingDrag a list into order of preference. options are the things being ranked.
Requires options.
How it gets answered — extracted from free text by the agent, then re-validated.
Configuration
Fields specific to ranking. The fields every block has — id, ref, title, required, visibility, media, agentHints, prefillParam, identityField — are documented once.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"buttonLabel": {
"type": "string",
"maxLength": 60
},
"type": {
"type": "string",
"const": "ranking"
},
"items": {
"minItems": 2,
"maxItems": 12,
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"minLength": 6,
"maxLength": 32
},
"label": {
"type": "string",
"minLength": 1,
"maxLength": 300
}
},
"required": [
"id",
"label"
]
}
}
},
"required": [
"id",
"ref",
"title",
"type",
"items"
],
"$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"
]
}
}
}What you receive
GET /v1/forms/{id} and every "next question" projects blocks through toPublicBlock. For the example above:
{
"id": "blk_rank0001",
"ref": "q_priorities",
"type": "ranking",
"title": "Rank these",
"required": true,
"imageKey": null,
"media": null,
"items": [
{
"id": "opt_price001",
"label": "Price"
},
{
"id": "opt_speed001",
"label": "Speed"
},
{
"id": "opt_supp0001",
"label": "Support"
}
]
}What you send
Every item's id exactly once, best first.
type Answer = string[];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_priorities", "value": ["opt_speed001","opt_price001","opt_supp0001"]}'What gets stored
The value is normalised before it is saved, so what you read back is not always what you sent.
| You send | Stored | |
|---|---|---|
["opt_speed001","opt_price001","opt_supp0001"] | ["opt_speed001","opt_price001","opt_supp0001"] |
Errors
| Code | When | Message |
|---|---|---|
required | an empty answer on a required block | This question needs an answer. |
incomplete_ranking | ["opt_speed001"] — a partial ranking is not an ordering | Please rank all the items. |
invalid_ranking | ["opt_speed001","opt_speed001","opt_price001"] | Each item can only be ranked once. |