Add questions to a survey
const url = 'https://app.surveyrock.com/api/v1/surveys/example/questions';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"questions":[{"type":"text_input","text":"example","subject":"example","helpText":"example","required":false,"choices":["example"],"multipleAnswers":false,"rows":["example"],"columns":["example"],"pageTitle":"example","mostLabel":"example","leastLabel":"example","itemsPerSet":1,"exposuresPerItem":1}],"pageId":"example"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://app.surveyrock.com/api/v1/surveys/example/questions \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "questions": [ { "type": "text_input", "text": "example", "subject": "example", "helpText": "example", "required": false, "choices": [ "example" ], "multipleAnswers": false, "rows": [ "example" ], "columns": [ "example" ], "pageTitle": "example", "mostLabel": "example", "leastLabel": "example", "itemsPerSet": 1, "exposuresPerItem": 1 } ], "pageId": "example" }'Add questions after the survey’s last question, or after the last question of the page named by pageId. Each is the question the survey editor would make for its type, with that type’s defaults; the list takes the same fields as createSurvey’s questions. A question with pageTitle starts a new page at the end of the survey, so pageTitle is refused when pageId names a page other than the last. All or nothing: the list is checked whole first; any problem is a 422 naming each question at fault, and more questions than the plan allows on one survey (counting those it has) is a 403 quota_exceeded. Either way nothing is written. A published survey keeps collecting with its published questions until it is published again. Not idempotent: send an Idempotency-Key so a retry does not add the questions twice.
Authorizations
Section titled “Authorizations”Parameters
Section titled “ Parameters ”Path Parameters
Section titled “Path Parameters”Survey ID
Header Parameters
Section titled “Header Parameters”1 to 128 characters, chosen by the caller. Recommended: adding questions is not idempotent, and a retry with the same key and body replays the first response instead of adding them twice; the same key with a different body is a 409
Request Bodyrequired
Section titled “Request Bodyrequired”object
The questions to add, in order. Each takes the fields of createSurvey’s questions items: type (required), text (required), helpText, required, choices, multipleAnswers, rows, columns, pageTitle, subject (nps only; an NPS question asks the standard sentence about its subject, not its text), mostLabel, leastLabel, itemsPerSet and exposuresPerItem (maxdiff only). The response gives each question’s text as respondents will see it.
object
Question type. text_input is a free-text answer, rating_scale a rating scale, ranking puts choices in order, matrix asks rows against columns. maxdiff (MaxDiff, best-worst scaling; Growth plan and above, otherwise a 403 feature_locked) shows its choices a few at a time and asks for the most and least important of each set; give it 6 to 30 short items of the same kind, one idea each, none negated, and no “None of these” or “Other”.
The question as respondents read it. Except for nps: an NPS question always asks the standard sentence, “How likely is it that you would recommend [subject] to a friend or colleague?”, so its text is not shown; set subject instead.
For nps only: who or what is recommended, e.g. “us” or “our support team”. Leave it out for “this company”. Refused on other types.
Optional guidance shown under the question.
Whether a respondent must answer it.
The answer options, for multiple_choice and ranking; the items, for maxdiff (6 to 30; none gives the editor’s six placeholder items). Ignored for other types.
For multiple_choice: let respondents pick more than one. Ignored for other types.
For matrix and slider: the statements rated. None gives the editor’s three placeholder rows. Ignored for other types.
For matrix: the answer columns. None keeps the editor’s standard scale. Ignored for other types.
Start a new page at this question, with this title.
For maxdiff only: the wording of the “most” pick, e.g. “Most appealing”. Leave it out for “Most important”. The two labels name one thing and its opposite. Refused on other types.
For maxdiff only: the wording of the “least” pick, e.g. “Least appealing”. Leave it out for “Least important”. Refused on other types.
For maxdiff only: items shown in each set. Leave it out for the recommended size for the number of items. Refused on other types.
For maxdiff only: how many times each respondent sees each item. Leave it out for the recommended number, which keeps a respondent to about 12 sets. Refused on other types.
The question page to add to (each element in listSurveyElements carries its page_id). Leave it out to add to the last page.
Responses
Section titled “ Responses ”Questions added
object
object
Each question added, in the request’s order, with its new element id and the page it is on.
object
Standard response metadata
object
Response timestamp in ISO 8601 format
API version
Unique request identifier
The resource’s ETag, on a read, create or update of a survey, element, rating or NPS question, distributor or contact. The same value as the ETag response header. Treat it as opaque and send it back as If-Match on the next update.
Example
{ "success": true, "meta": { "version": "3.0" }}Forbidden: the token or its owner may not edit this survey; or (error code quota_exceeded; details give limit, requested and required_plan) the survey would hold more questions than the plan allows. Nothing is written.
Standard error response format
object
object
Stable, snake_case domain code – see ApiErrorHandler::EXCEPTION_MAP and DomainException
Human-readable error message
Imperative recovery hint for this domain code – see ApiErrorHandler::DOMAIN_CODE_SUGGESTIONS
Whether retrying the identical request might succeed without any change on the caller’s end
Additional, code-specific error details
object
Standard response metadata
object
Response timestamp in ISO 8601 format
API version
Unique request identifier
The resource’s ETag, on a read, create or update of a survey, element, rating or NPS question, distributor or contact. The same value as the ETag response header. Treat it as opaque and send it back as If-Match on the next update.
Example
{ "success": false, "error": { "code": "survey_not_found" }, "meta": { "version": "3.0" }}Validation failed: questions is missing or names the questions at fault, or pageId is not one of the survey’s question pages
Validation error response with field-specific errors
object
object
Field-specific validation errors
object
Standard response metadata
object
Response timestamp in ISO 8601 format
API version
Unique request identifier
The resource’s ETag, on a read, create or update of a survey, element, rating or NPS question, distributor or contact. The same value as the ETag response header. Treat it as opaque and send it back as If-Match on the next update.
Example
{ "success": false, "error": { "code": "validation_failed", "message": "Validation failed", "suggestion": "Fix the fields listed in details and re-submit.", "retryable": false }, "meta": { "version": "3.0" }}