Developers
Build on Polls
Everything the Polls builder does goes through a public REST API, so anything you can do in the browser you can script. Keep surveys as files in git, check them in CI, and publish them from the command line.
REST API
JSON over HTTPS, described by an OpenAPI 3.1 document. Authenticate with a personal API token.
Surveys as YAML
Write a survey in any editor, with completion and checking from a JSON Schema. Import it, export it back.
Base URL
All examples use https://polls.thermals.app. https://polls.skywardfederal.com serves the same API and the same accounts; use whichever host you sign in on. Every path in this guide is relative to it, for example https://polls.thermals.app/api/surveys.
Downloads
| File | What it is |
|---|---|
openapi.json | The OpenAPI 3.1 document for the whole API. Generate a client from it, or import it into an HTTP tool. |
survey.schema.json | JSON Schema for survey files, for editor completion and checking. |
polls.mjs | The command line tool. Needs Node.js 20 or newer, nothing else. |
examples/starter.yaml | A small, commented survey to start from. |
examples/team-pulse.yaml | An agreement-scale pulse survey that shares one scale across its questions. |
examples/every-question-type.yaml | One question of each of the twelve types, with their options. |
Quick start
From nothing to a published survey and its results, with curl. Five minutes.
1. Get a token
Sign in and mint a token at /app/tokens. It is shown once: copy it into your shell (or your secret store) straight away.
export POLLS=https://polls.thermals.app
export POLLS_TOKEN=polls_... # paste your token
2. List your surveys
curl -s "$POLLS/api/surveys" -H "Authorization: Bearer $POLLS_TOKEN"
The answer is { "items": [ ... ] }, newest first. A 401 unauthorized means the token is missing, mistyped, expired or revoked.
3. Write a survey
Save this as survey.yaml. The first line is optional: it lets editors check the file as you type (see Editor setup).
# yaml-language-server: $schema=https://polls.thermals.app/developers/survey.schema.json
polls: 1
title: Lunch poll
slug: lunch-poll
questions:
- id: q_food
type: single_choice
title: Pizza or tacos?
required: true
choices:
- pizza: Pizza
- tacos: Tacos
- id: q_why
type: long_text
title: Why?
4. Import and publish it
Check it first with dryRun=true (nothing is saved), then import and publish in one step:
curl -s "$POLLS/api/surveys/import?dryRun=true&publish=true" \
-H "Authorization: Bearer $POLLS_TOKEN" \
-H 'Content-Type: application/yaml' \
--data-binary @survey.yaml
curl -s "$POLLS/api/surveys/import?publish=true" \
-H "Authorization: Bearer $POLLS_TOKEN" \
-H 'Content-Type: application/yaml' \
--data-binary @survey.yaml
The second call answers 201 with the new survey. Its id (srv_...) is what the other endpoints take, and the survey is live at https://polls.thermals.app/s/lunch-poll. Use --data-binary, not -d: -d strips the newlines that YAML depends on.
5. Read the results
export SURVEY=srv_... # the id from step 4
# Totals per question
curl -s "$POLLS/api/surveys/$SURVEY/summary" -H "Authorization: Bearer $POLLS_TOKEN"
# Every response, 50 at a time (see Pagination)
curl -s "$POLLS/api/surveys/$SURVEY/responses?limit=50" -H "Authorization: Bearer $POLLS_TOKEN"
# Everything as a spreadsheet
curl -s "$POLLS/api/surveys/$SURVEY/responses/export" -H "Authorization: Bearer $POLLS_TOKEN" -o responses.csv
The same with the CLI
curl -O https://polls.thermals.app/developers/polls.mjs
export POLLS_TOKEN=polls_...
node polls.mjs check survey.yaml # offline: every problem, with line numbers
node polls.mjs push survey.yaml --publish # import and publish; prints the link
node polls.mjs list # your polls
Authentication
Public endpoints (/api/public/* and /healthz) need no credentials. Everything else needs an API token (scripts, CI, integrations) or a browser session (the Polls web app).
API tokens
- Mint and revoke them while signed in at /app/tokens. Give each one a name that says where it is used.
- A token is
polls_followed by 43 base64url characters. It is shown once; Polls keeps only a SHA-256 hash of it, so a lost token cannot be recovered, only replaced. - A token acts as you: it can read, change and delete every survey and response you can. Treat it like a password.
- It lasts 90 days unless you choose otherwise (1 to 365 days), and stops working the moment you revoke it.
- Tokens cannot manage tokens: listing, minting and revoking need a browser session, and a token gets
403 forbiddenthere.
Sending a token
curl -s "$POLLS/api/me" -H "Authorization: Bearer $POLLS_TOKEN"
const res = await fetch('https://polls.thermals.app/api/me', {
headers: { Authorization: `Bearer ${process.env.POLLS_TOKEN}` },
});
if (!res.ok) {
const { error } = await res.json();
throw new Error(`${res.status} ${error.code}: ${error.message}`);
}
console.log(await res.json()); // { sub, name, email, via: "token" }
A missing, malformed, expired or revoked token is 401 unauthorized. A survey that is not yours answers 404 not_found, exactly as if it did not exist.
Never put a token in a URL
Polls reads tokens only from the Authorization header. Query strings end up in shell history, proxy logs and Referer headers. Keep tokens in environment variables or your CI's secret store, never in a committed file.
Browser sessions
Signing in at /auth/login sets the __Host-polls_session cookie (HttpOnly, Secure, SameSite=Lax). It ends after 8 hours idle or 7 days in total. Sessions are for the web app; scripts should use a token. If a request carries both, the token is used and the cookie is ignored.
The CSRF rule for cookie requests
A request authenticated by the session cookie, with any method other than GET or HEAD, must send an Origin header equal to https://polls.thermals.app or https://polls.skywardfederal.com and, when it has a body, Content-Type: application/json. Anything else is 403 forbidden. Browsers do this for same-origin fetch calls; token requests are exempt.
Survey YAML
A survey as a file: write it in any editor, generate it from any language, keep it in git, check it offline, import it into Polls and export it back. This is format 1.
A complete example
# yaml-language-server: $schema=https://polls.thermals.app/developers/survey.schema.json
polls: 1
title: Skyward 30-day pulse
slug: skyward-pulse
description: >
Thinking about the past 30 days, how strongly do you agree with each
statement? Choose "Not enough visibility" when appropriate.
settings:
thankYou:
title: Thank you
message: Your answers are in.
defaults:
required: true
scales:
agreement:
- sd: Strongly disagree
- d: Disagree
- n: Neither agree nor disagree
- a: Agree
- sa: Strongly agree
- nv: Not enough visibility
questions:
- id: q01_direction
type: single_choice
title: When priorities competed, people knew which work mattered most to Skyward.
description: Direction.
choices: agreement
- id: q10_repeat
type: long_text
title: What worked especially well this month that Skyward should repeat?
required: false
maxLength: 3000
The document
One YAML mapping. Keys, in the order an export writes them:
| Key | Required | Meaning |
|---|---|---|
polls | yes | The format version. Always 1. |
title | yes | 1 to 200 characters. |
slug | no | The public link, /s/<slug>: 3 to 50 of a-z, 0-9, -, not starting or ending with -. Left out, Polls picks a random one. |
description | no | Up to 2000 characters, shown on the welcome screen. |
settings | no | See Settings. Anything left out takes the default. |
defaults | no | Values every question gets unless it says otherwise. Only required (true or false) for now. |
scales | no | Named choice lists that questions use by name. See Choices and scales. |
questions | yes | A list of 0 to 100 questions (at least 1 to publish). |
Unknown keys are errors, anywhere in the document, so a typo such as requird: true is reported instead of silently ignored.
Settings
| Key | Default | Meaning |
|---|---|---|
welcome | { enabled: true, buttonLabel: Start } | The welcome screen. welcome: false turns it off; welcome: true is the default. |
welcome.enabled | true | Show the welcome screen. |
welcome.buttonLabel | Start | 1 to 24 characters. |
thankYou.title | Thank you! | 1 to 200 characters. |
thankYou.message | Your answers are in. | Up to 2000 characters. |
theme.accent | "#3D5AFE" | A colour #RRGGBB. Quote it: in YAML an unquoted # starts a comment. |
theme.mode | light | light or dark. |
showProgress | true | Show the progress bar. |
closesAt | null | Stop taking answers at this time: ISO 8601 with a time zone, such as 2027-01-31T17:00:00Z. |
maxResponses | null | Stop after this many answers, 1 to 1,000,000. |
Questions
Every question has:
| Key | Required | Meaning |
|---|---|---|
id | no | 1 to 40 of a-z, 0-9, _, unique in the survey. Answers and CSV columns are keyed by it, so set it if you will ever re-import or compare results. Left out, it becomes q<position> (q1, q2, …; q3_2 if q3 is taken). |
type | yes | One of the twelve types below. |
title | yes | 1 to 500 characters. The question itself. |
description | no | Up to 1000 characters, shown under the title. |
required | no | true or false. Defaults to defaults.required, else false. Ignored for statement. |
And, by type (defaults in brackets):
type | Extra keys (all optional) | Takers answer with |
|---|---|---|
short_text | maxLength 1..1000 (255), placeholder ≤ 100 | a line of text |
long_text | maxLength 1..10000 (5000), placeholder ≤ 100 | a paragraph |
email | placeholder | an email address |
number | min, max, integerOnly (false) | a number |
single_choice | choices (required, 2..50), allowOther (false) | one choice, or their own text if allowOther |
multiple_choice | choices (required, 2..50), allowOther (false), minSelections, maxSelections | one or more choices |
dropdown | choices (required, 2..500) | one choice from a list |
yes_no | none | yes or no |
rating | steps 3..10 (5) | stars, 1..steps |
opinion_scale | start 0 or 1 (0), end 5..10 (10), labels: { left, right } (≤ 40 each) | a number start..end |
date | none | a date |
statement | buttonLabel ≤ 24 (Continue) | nothing: a screen of text between questions |
A key that does not belong to the question's type is an error.
Choices and scales
choices is either a list or the name of a scale. Each item of a list is one of:
choices:
- Red # just a label: the id is made from it ("red")
- gb: Great Britain # id: label
- id: other_place # the long form
label: Somewhere else
An id made from a label is the label in lower case, with accents removed, every run of other characters turned into _, trimmed and cut to 40 characters ("Neither agree nor disagree" becomes neither_agree_nor_disagree). If nothing is left, or the result is a reserved name, the id is c<position>. Repeats get _2, _3, …. Choice ids key the answers, like question ids, so write them out (- sd: Strongly disagree) if labels may change later.
A scale is a choice list with a name, defined once under scales and used by any number of questions. Scale names follow the id rules, and using a scale is exactly the same as writing its list out in every question that names it.
scales:
agreement: [Strongly disagree, Disagree, Neutral, Agree, Strongly agree]
questions:
- { type: single_choice, title: The plan is clear., choices: agreement }
- { type: single_choice, title: I know what I own., choices: agreement }
The YAML Polls reads
YAML 1.2 with the core schema, minus the parts that make files surprising or unsafe:
- Supported: block mappings and lists; flow
[a, b]and{ k: v }(on one line or several); plain,'single'and"double"quoted strings (with\n,\t,\",\\,\uXXXXescapes); literal|and folded>blocks with-and+chomping;#comments. true,false,null,~and decimal numbers are what they look like. Everything else is a string:yes,no,on,off,NO(the country code), dates and times all stay text.- Refused with an error: anchors (
&a), aliases (*a), tags (!!str), merge keys (<<), more than one document (---is allowed once, at the top), directives (%YAML), duplicate keys, and tabs used for indentation. - At most 512 KB of text and 32 levels of nesting.
Quote colours
accent: #3D5AFE is an empty value followed by a comment. Write accent: "#3D5AFE".
A JSON document in the same shape ({"polls": 1, "title": …}) is accepted too, so any language can write a survey with its JSON library.
Editor setup
Put this as the first line of a survey file and any editor that speaks the YAML language server, such as VS Code with the YAML extension by Red Hat, completes keys, shows their descriptions and underlines mistakes as you type:
# yaml-language-server: $schema=https://polls.thermals.app/developers/survey.schema.json
Or map a whole folder once, in VS Code's settings.json:
"yaml.schemas": {
"https://polls.thermals.app/developers/survey.schema.json": "surveys/*.yaml"
}
The schema catches shape mistakes. A few rules (unique ids, scale names that exist, the YAML subset above) are only checked by Polls itself, so run node polls.mjs check too.
Errors, with line numbers
Every problem names where it is, as a path and, for YAML, a line:
pulse.yaml:14 questions[2].choices: must have between 2 and 50 choices
pulse.yaml:3 slug: must be 3 to 50 of a-z, 0-9 and -, not starting or ending with -
Paths are the same ones the JSON API uses (questions[2].choices[0].label). A problem inside a scale used by a question is reported at the scale. Over the API the same problems come back as 400 validation_failed, each detail with path, message and, when known, line.
Importing and exporting over the API
POST /api/surveys/import creates a new draft survey from a file. Send it either way:
Content-Type: application/yaml(ortext/yaml) with the file as the body. API tokens only, for scripts:curl --data-binary @pulse.yaml.Content-Type: application/jsonwith{ "yaml": "<the file's text>" }. Works with API tokens and from the browser.
| Query parameter | Effect |
|---|---|
dryRun=true | Check only, save nothing: 200 { "ok": true, "survey": <definition>, "slug": "…" | null }, or 400 validation_failed with the problems. Checks with the publish rules if publish=true too. |
publish=true | Create and publish in one step (needs at least one question). |
slug=<slug> | Use this link instead of the file's. slug= (empty) means a random one. |
It answers 201 with the survey (as GET /api/surveys/{id} returns it), 400 validation_failed, 409 slug_taken, or 413 payload_too_large past 512 KB.
GET /api/surveys/{id}/export returns the survey's draft as application/yaml; charset=utf-8, as an attachment named <slug>.yaml:
curl -s "$POLLS/api/surveys/$SURVEY/export" -H "Authorization: Bearer $POLLS_TOKEN" -o survey.yaml
In the builder, Import is on the polls list (choose or paste a file, Check, then Import) and Export YAML is on each poll.
What an export looks like
An export is the shortest file that imports back to exactly the same survey (same ids, same order, same settings):
- settings, question keys and per-type options at their defaults are left out, and so is an empty
description; defaults.requiredis set to what most questions use, and only the questions that differ sayrequired:;- a choice list used by two or more questions becomes a scale (
scale_1,scale_2, …); - choices whose ids are what their labels would make are written as bare labels; otherwise every choice in the list is written
id: label; - every question's
idis written.
Example files
starter.yaml: a small, commented survey to start from.team-pulse.yaml: an agreement-scale pulse survey built on one shared scale.every-question-type.yaml: one question of each type, with their options.
CLI
polls.mjs is one file with no dependencies. It needs Node.js 20 or newer.
curl -O https://polls.thermals.app/developers/polls.mjs
node polls.mjs check survey.yaml
Commands
check, json, yaml and new work offline. push, pull and list call the API and need POLLS_TOKEN.
| Command | What it does |
|---|---|
node polls.mjs new > survey.yaml | Writes a commented starter file. --title "…" gives it your title. |
node polls.mjs check survey.yaml | Checks files offline, with the rules for publishing, and prints every problem with its line number. Give it as many files as you like. |
node polls.mjs json survey.yaml | Prints the normalised definition as JSON, ids and defaults filled in. The output is a survey file too (it starts "polls": 1). |
node polls.mjs yaml survey.json | Turns JSON (format 1, or a survey as the API returns it) into YAML. |
node polls.mjs push survey.yaml --publish | Checks the file offline, imports it as a new survey and prints its id and link. Leave out --publish to create a draft. --slug my-link uses another link than the file's (--slug= for a random one); --dry-run has the server check it and saves nothing. |
node polls.mjs pull srv_... > survey.yaml | Exports a survey's draft as YAML. --out survey.yaml writes the file itself. |
node polls.mjs list | Lists your polls: id, status, responses, link and title. |
Environment
| Variable | Meaning |
|---|---|
POLLS_TOKEN | Your API token (polls_...), from /app/tokens. Needed by push, pull and list. |
POLLS_URL | The server. Default https://polls.thermals.app; set https://polls.skywardfederal.com to use that host. It must be https://: the CLI will not send your token in the clear (or across a redirect), and never prints it. |
Exit codes
0 when the command succeeded. check exits 1 when any file has problems, which is what makes it useful in CI; a network or API error is 1 too. A bad command line, a missing POLLS_TOKEN or an unusable POLLS_URL is 2. The reason is always on stderr.
In CI
Keep surveys in a surveys/ folder and check every change. For example, a GitHub Actions workflow:
# .github/workflows/surveys.yml
name: surveys
on: [push, pull_request]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: curl -fsSO https://polls.thermals.app/developers/polls.mjs
- run: node polls.mjs check surveys/*.yaml
To avoid the download, commit polls.mjs next to your surveys. To publish from CI as well, store a token as a secret and pass it as POLLS_TOKEN to a node polls.mjs push step.
Errors and limits
Every error looks the same
{
"error": {
"code": "validation_failed",
"message": "The request body is not valid.",
"details": [
{ "path": "questions[2].choices", "message": "must have at least 2 items" }
]
}
}
error.code is stable: branch on it, not on message. details appears when there is something to point at.
| HTTP | code | Meaning |
|---|---|---|
| 400 | bad_request, validation_failed | The request could not be read, or its content breaks a rule (with details). |
| 401 | unauthorized | No valid session or token. |
| 403 | forbidden | Bad origin (the CSRF rule), a token used where a session is required, or a host that is not allowed. |
| 404 | not_found | No such thing, or a survey that is not yours. |
| 405 | method_not_allowed | The path exists but not with this method; see the Allow header. |
| 409 | version_conflict, slug_taken, survey_changed, survey_closed | Someone saved first, the link is in use, the survey was republished, or it no longer takes answers. |
| 413 | payload_too_large | The body is over its limit (below). |
| 429 | rate_limited | Too many requests; wait Retry-After seconds. |
| 500 | internal | Our fault. No detail is leaked. |
| 503 | unavailable | The data store is busy. Nothing changed; retry after Retry-After (1 second). |
Saving: versions and conflicts
Every survey has a version that goes up on each save. PUT /api/surveys/{id} replaces the whole draft and must send the version it edited; if anyone saved in between, the answer is 409 version_conflict and nothing changes. Fetch the survey again, reapply your change and retry.
Rate limits
- Response submissions: 200 per survey per hour and 600 per hour across all surveys, per viewer IP address.
- Everything else is limited per IP address at the edge, at a level ordinary scripts do not reach.
Over a limit you get 429 rate_limited. Wait for Retry-After seconds when it is present; otherwise back off and retry.
Size limits
| What | Limit |
|---|---|
POST /api/surveys/import body | 512 KB of YAML |
| A response submission | 64 KB |
| Any other request body | 320 KB |
| A survey definition | 256 KB, up to 100 questions |
| CSV export | 5 MB; past that, page through GET /api/surveys/{id}/responses |
Bodies over a limit get 413 payload_too_large.
Pagination
GET /api/surveys/{id}/responses returns { "items": [...], "nextCursor": "..." }, newest first. Pass nextCursor back as cursor until it is null. limit is 1 to 200 (default 50). Survey and token lists are not paginated.
let cursor = null;
do {
const url = new URL(`https://polls.thermals.app/api/surveys/${surveyId}/responses`);
url.searchParams.set('limit', '200');
if (cursor) url.searchParams.set('cursor', cursor);
const res = await fetch(url, { headers: { Authorization: `Bearer ${process.env.POLLS_TOKEN}` } });
const page = await res.json();
for (const response of page.items) console.log(response.id);
cursor = page.nextCursor;
} while (cursor);
API reference
Loading the API reference…