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":[{}],"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": [ {} ], "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). The response gives each question’s text as respondents will see it.
object
The question page to add to (each element in listSurveyElements carries its page_id). Leave it out to add to the last page.
Examplegenerated
{ "questions": [ {} ], "pageId": "example"}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" }}