add_numeric_expression
Create a Numeric Expression — Settings > Assignment & Formulas > Numeric Expressions > Create Expression in the builder. A Numeric Expression is a named, computed number built from question scores (and, optionally, other already-created expressions) combined with +, -, *, / and parenthesized grouping, given here as a structured terms list instead of free text; ordinary arithmetic precedence applies (* and / bind tighter than + and - unless grouped). Example: total = 20 + Q1 - Q6 is terms: [{value:20}, {questionId, operator:"+"}, {questionId, operator:"-"}]; and ratio = trait-score / Q3 * 100 (using an earlier expression) is [{expressionId}, {questionId, operator:"/"}, {value:100, operator:"*"}]. Each term is exactly one of a question (questionId/position), another expression (expressionId/expressionLabel — must already be defined EARLIER in the survey's expression list; a forward reference is refused with a clear error), a literal number (value), or a parenthesized sub-formula (group, itself an array of terms — use this when precedence needs forcing, e.g. (a + b) / c). Unanswered questions count as 0, and a divide-by-zero result is displayed as 0, as in the builder. Optionally add conditional overrides via conditions: each is an "IF when conditions match, THEN use thenTerms instead of the base formula" rule (same condition shape as add_display_logic's). If none of the conditions match for a given respondent, the base terms formula is used as the fallback, so it is still meaningful when conditions are present. recalculateFlag (default false) mirrors the builder's "Recalculate expression on the results screen" checkbox; executeOncePerResponse (default false) mirrors "Evaluate once and fix result" (freezes the value after the first successful computation instead of recomputing on every later answer). The response includes recallToken ({{exp:<id>}}) for later use — ONLY if the user separately asks to display this score somewhere (e.g. "show the total score on the thank you screen"), paste that exact string into update_question's label/description or update_thankyou_screen's title/description. Do not insert it anywhere on your own initiative just because the expression was created — creating the formula and displaying it are separate asks. Refused for the reserved built-in names (e.g. "score"), for "price" (already exists on every survey — use update_numeric_expression with expressionId: "price" instead), and for any name already used by another expression or a Text Variable.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"surveyId": "<surveyId>",
"label": "<label>",
"terms": "<terms>"
},
"name": "add_numeric_expression"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| label | Yes | The expression's name (letters, numbers, "-", "_" only, no spaces) — e.g. "total_score". This is how it's identified afterward and shown in the builder's recall list. | |
| terms | Yes | The formula's terms, applied in order — see the tool description for the term shapes and how operators/precedence work. | |
| teamId | No | Which team workspace to act in (ids come from get_account_info or list_surveys). Optional: if omitted, the server uses the team that owns the given surveyId, or your only team. Required for create_survey when you belong to several teams. | |
| surveyId | Yes | The Survey ID to add the expression to | |
| conditions | No | Optional conditional overrides — see the tool description. | |
| recalculateFlag | No | Recalculate this expression live on the results screen. Defaults to false. | |
| executeOncePerResponse | No | Freeze the computed value after the first time it's set for a given response, instead of recomputing on every later answer. Defaults to false. |