Method Signature
constructorio . quizzes . getQuizNextQuestion ( quizId , parameters , networkParameters )
Retrieves the next question from a quiz. On the first call, returns the initial question. On subsequent calls with answers provided, returns the next appropriate question based on the quiz logic.
Parameters
The unique identifier of the quiz.
Additional parameters to refine the request. An array of answers to previous questions. Each answer is itself an array. Format: [[1,2], [1], ["true"], ["seen"], [""]] Based on the question type:
Integer - For single/multiple choice questions (option IDs)
“true”/“false” - For boolean questions
“seen” - For cover questions
Empty string "" - For skipped questions
The section of the product catalog to query. This can be used to segment quiz results by product category.
Version identifier for the quiz. This is returned with the first request and must be passed with all subsequent requests to ensure consistency. Learn more about quiz versioning Session identifier for the quiz. This is returned with the first request and must be passed with all subsequent requests to maintain session state. Learn more about quiz sessions If true, tracking for this question will be skipped. This is useful for preloading the first question of a quiz without recording analytics.
Parameters relevant to the network request. Request timeout in milliseconds. If the request takes longer than this, it will be aborted.
Returns
Returns a Promise that resolves to a NextQuestionResponse object.
The next question object. The structure varies based on question type. Unique identifier for the question.
The question type. One of:
"single" - Single choice
"multiple" - Multiple choice
"single_filter_value" - Single filter value selection
"multiple_filter_values" - Multiple filter values selection
"open" - Open-ended text input
"cover" - Cover/informational screen
"free_form" - Free-form text input
The main question text displayed to the user.
Additional descriptive text for the question.
Call-to-action button text (e.g., “Next”, “Continue”).
Whether the user can skip this question.
Array of answer options (for single/multiple choice questions). Unique identifier for the option.
Display text for the option.
Associated product attribute (for filter questions). Images associated with the option. URL of the primary image.
Alt text for the primary image.
URL of the secondary image.
Alt text for the secondary image.
The filter name (for filter value questions).
Placeholder text for input fields (for open/free-form questions).
Images associated with the question itself.
Version identifier for the quiz. Must be included in all subsequent requests.
The identifier of the quiz.
Session identifier for the quiz. Must be included in all subsequent requests.
The total number of questions in the quiz.
Examples
Get First Question
const ConstructorIO = require ( '@constructor-io/constructorio-client-javascript' );
const constructorio = new ConstructorIO ({
apiKey: 'YOUR_API_KEY' ,
});
const response = await constructorio . quizzes . getQuizNextQuestion ( 'product-finder-quiz' );
console . log ( response . next_question . title );
// "What are you shopping for?"
// Store these for subsequent requests
const quizVersionId = response . quiz_version_id ;
const quizSessionId = response . quiz_session_id ;
const totalQuestions = response . total_questions ;
Get Next Question with Answers
// User answered the first question by selecting options 1 and 2
const response = await constructorio . quizzes . getQuizNextQuestion ( 'product-finder-quiz' , {
answers: [[ 1 , 2 ]],
quizVersionId: 'abc123' ,
quizSessionId: 'session456' ,
});
console . log ( response . next_question . title );
// Next question based on previous answers
Multiple Questions with Different Answer Types
// After multiple questions answered
const response = await constructorio . quizzes . getQuizNextQuestion ( 'product-finder-quiz' , {
answers: [
[ 1 , 2 ], // Multiple choice - selected options 1 and 2
[ 3 ], // Single choice - selected option 3
[ "true" ], // Boolean - answered true
[ "seen" ], // Cover question - acknowledged
],
quizVersionId: 'abc123' ,
quizSessionId: 'session456' ,
});
Skip Tracking for Preload
// Preload the first question without tracking
const response = await constructorio . quizzes . getQuizNextQuestion ( 'product-finder-quiz' , {
skipTracking: true ,
});
// Display the question to the user
// When they actually interact with it, make another call without skipTracking
With Section Filter
const response = await constructorio . quizzes . getQuizNextQuestion ( 'product-finder-quiz' , {
section: 'Men' ,
answers: [[ 1 ]],
quizVersionId: 'abc123' ,
quizSessionId: 'session456' ,
});
With Network Timeout
try {
const response = await constructorio . quizzes . getQuizNextQuestion (
'product-finder-quiz' ,
{
answers: [[ 1 , 2 ]],
quizVersionId: 'abc123' ,
quizSessionId: 'session456' ,
},
{
timeout: 5000 , // 5 seconds
}
);
} catch ( error ) {
console . error ( 'Request timed out or failed:' , error );
}
Handling Different Question Types
const response = await constructorio . quizzes . getQuizNextQuestion ( 'product-finder-quiz' );
const question = response . next_question ;
switch ( question . type ) {
case 'single' :
// Render radio buttons
console . log ( 'Select one:' , question . options );
break ;
case 'multiple' :
// Render checkboxes
console . log ( 'Select all that apply:' , question . options );
break ;
case 'open' :
// Render text input
console . log ( 'Enter your answer:' , question . input_placeholder );
break ;
case 'cover' :
// Render informational screen
console . log ( question . title , question . description );
break ;
case 'single_filter_value' :
case 'multiple_filter_values' :
// Render options that map to product filters
console . log ( `Filter: ${ question . filter_name } ` );
console . log ( 'Options:' , question . options );
break ;
}
Error Handling
try {
const response = await constructorio . quizzes . getQuizNextQuestion ( 'quiz-id' , {
answers: [[ 1 , 2 ]],
quizVersionId: 'abc123' ,
quizSessionId: 'session456' ,
});
} catch ( error ) {
if ( error . message === 'quizId is a required parameter of type string' ) {
console . error ( 'Quiz ID is required' );
} else if ( error . message === 'getQuizNextQuestion response data is malformed' ) {
console . error ( 'Invalid response from server' );
} else {
console . error ( 'Request failed:' , error );
}
}
Notes
Always store quiz_version_id and quiz_session_id from the first response and include them in all subsequent requests
The answers array should contain one entry per question answered, in order
Use skipTracking: true when preloading questions to avoid inflating analytics
The response will throw an error if quiz_version_id is not present, indicating a malformed response
Question types determine which fields are available in the next_question object
API Reference