Short text
One line of free text: a name, a job title, a company.
short_textOne line of free text: a name, a job title, a company.
How it gets answered — extracted from free text by the agent, then re-validated.
Configuration
Fields specific to short_text. 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": "short_text"
},
"unique": {
"default": false,
"type": "boolean"
},
"minLength": {
"default": 0,
"type": "integer",
"minimum": 0,
"maximum": 500
},
"maxLength": {
"default": 500,
"type": "integer",
"minimum": 1,
"maximum": 500
},
"pattern": {
"type": "string",
"maxLength": 500
},
"placeholder": {
"type": "string",
"maxLength": 200
}
},
"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: pattern=<regular expression> when the author describes a SHAPE the answer must have, such as a student number like 1MS22CS045, an order id, a vehicle registration, a postcode. Write a real JavaScript regex anchored with ^ and $ (pattern=^1MS\d{2}[A-Z]{2}\d{3}$), and only when the author actually stated the format; never guess one, because a pattern nobody asked for refuses answers that were correct. 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:
{
"id": "blk_short001",
"ref": "q_company",
"type": "short_text",
"title": "Company name?",
"required": true,
"imageKey": null,
"media": null,
"identityField": "organization",
"maxLength": 40
}What you send
One line of text, trimmed.
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_company", "value": " Northwind "}'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 | |
|---|---|---|
" Northwind " | "Northwind" | trimmed before storage |
Errors
| Code | When | Message |
|---|---|---|
required | "" | This question needs an answer. |
type | 42 | Please answer with text. |
too_short | "N" | Answer must be at least 2 characters. |
too_long | "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | Answer must be at most 40 characters. |
pattern | — | |
duplicate | unique is on and another response already gave this answer | Someone has already used that — please try a different one. |