Method Signature
constructorio . quizzes . getQuizResults ( quizId , parameters , networkParameters )
Retrieves personalized product recommendations and filter expressions based on the complete set of quiz answers. This method should be called after all quiz questions have been answered.
Parameters
The unique identifier of the quiz.
Parameters for the quiz results request. An array of all answers to quiz 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
This parameter is required and must contain at least one answer. The section of the product catalog to query. This can be used to segment results by product category.
The page number of results to return. Use for pagination. Defaults to 1.
The number of results to return per page. Use with page for pagination.
Key/value mapping of filters to refine results. Each key is a filter name and each value is an array of filter values. Example: {
"Brand" : [ "Nike" , "Adidas" ],
"Color" : [ "Red" ]
}
Key/value mapping of options for result formatting. Array of hidden metadata field names to return in results.
Array of field names to return in results.
Convenience parameter for hidden metadata fields to return. If provided, this will be merged into fmtOptions.hidden_fields.
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 QuizResultsResponse object.
The request parameters that were sent. Number of results per page.
Sort order (ascending/descending).
collection_filter_expression
Filter expression applied to the collection.
Search term if applicable.
The response data containing results and metadata. Array of product results matching the quiz answers. Product data. Additional product fields.
Terms that matched this result.
Whether this result is in a slotted position.
Labels associated with the result.
Total number of results available (across all pages).
Available facets for filtering results.
Result groups if grouping is enabled.
Available sorting options.
Refined content suggestions.
Information about result sources.
Active features for this response.
Unique identifier for this result set. Used for analytics tracking.
Version identifier for the quiz.
Session identifier for the quiz.
The identifier of the quiz.
Information about the selected options and their matching status. Whether this option has an associated product attribute.
Whether this option contributed to the results.
Examples
Basic Usage
const ConstructorIO = require ( '@constructor-io/constructorio-client-javascript' );
const constructorio = new ConstructorIO ({
apiKey: 'YOUR_API_KEY' ,
});
const results = await constructorio . quizzes . getQuizResults ( 'product-finder-quiz' , {
answers: [
[ 1 , 2 ], // First question: selected options 1 and 2
[ 3 ], // Second question: selected option 3
[ "true" ], // Third question: answered true
[ "seen" ], // Fourth question: acknowledged cover
],
quizVersionId: 'abc123' ,
quizSessionId: 'session456' ,
});
console . log ( results . response . results );
// Array of recommended products
console . log ( results . response . total_num_results );
// Total number of matching products
With Section Filter
const results = await constructorio . quizzes . getQuizResults ( 'product-finder-quiz' , {
answers: [[ 1 , 2 ], [ 3 ], [ "true" ]],
section: 'Women' ,
quizVersionId: 'abc123' ,
quizSessionId: 'session456' ,
});
// Get first page with 20 results
const page1 = await constructorio . quizzes . getQuizResults ( 'product-finder-quiz' , {
answers: [[ 1 , 2 ], [ 3 ]],
quizVersionId: 'abc123' ,
quizSessionId: 'session456' ,
page: 1 ,
resultsPerPage: 20 ,
});
console . log ( `Showing ${ page1 . response . results . length } of ${ page1 . response . total_num_results } ` );
// Get second page
const page2 = await constructorio . quizzes . getQuizResults ( 'product-finder-quiz' , {
answers: [[ 1 , 2 ], [ 3 ]],
quizVersionId: 'abc123' ,
quizSessionId: 'session456' ,
page: 2 ,
resultsPerPage: 20 ,
});
With Additional Filters
const results = await constructorio . quizzes . getQuizResults ( 'product-finder-quiz' , {
answers: [[ 1 , 2 ], [ 3 ]],
quizVersionId: 'abc123' ,
quizSessionId: 'session456' ,
filters: {
'Brand' : [ 'Nike' , 'Adidas' ],
'Color' : [ 'Red' , 'Blue' ],
'Price Range' : [ '$50-$100' ],
},
});
With Hidden Fields
const results = await constructorio . quizzes . getQuizResults ( 'product-finder-quiz' , {
answers: [[ 1 , 2 ], [ 3 ]],
quizVersionId: 'abc123' ,
quizSessionId: 'session456' ,
hiddenFields: [ 'internal_id' , 'cost_price' , 'supplier' ],
});
// Access hidden fields in results
results . response . results . forEach ( product => {
console . log ( product . data . internal_id );
console . log ( product . data . cost_price );
});
const results = await constructorio . quizzes . getQuizResults ( 'product-finder-quiz' , {
answers: [[ 1 , 2 ], [ 3 ]],
quizVersionId: 'abc123' ,
quizSessionId: 'session456' ,
fmtOptions: {
hidden_fields: [ 'internal_id' ],
fields: [ 'id' , 'title' , 'price' , 'image_url' ],
},
});
Complete Quiz Flow
const ConstructorIO = require ( '@constructor-io/constructorio-client-javascript' );
const constructorio = new ConstructorIO ({
apiKey: 'YOUR_API_KEY' ,
});
// Step 1: Get first question
const firstQuestion = await constructorio . quizzes . getQuizNextQuestion ( 'product-finder-quiz' );
const quizVersionId = firstQuestion . quiz_version_id ;
const quizSessionId = firstQuestion . quiz_session_id ;
// Store answers as user progresses
const answers = [];
// Step 2: User answers first question
answers . push ([ 1 , 2 ]);
// Get next question
const secondQuestion = await constructorio . quizzes . getQuizNextQuestion ( 'product-finder-quiz' , {
answers ,
quizVersionId ,
quizSessionId ,
});
// Step 3: User answers second question
answers . push ([ 3 ]);
// Get next question
const thirdQuestion = await constructorio . quizzes . getQuizNextQuestion ( 'product-finder-quiz' , {
answers ,
quizVersionId ,
quizSessionId ,
});
// Step 4: User answers third question
answers . push ([ "true" ]);
// Step 5: All questions answered, get results
const results = await constructorio . quizzes . getQuizResults ( 'product-finder-quiz' , {
answers ,
quizVersionId ,
quizSessionId ,
resultsPerPage: 24 ,
});
console . log ( `Found ${ results . response . total_num_results } products` );
console . log ( 'Top recommendations:' , results . response . results . slice ( 0 , 5 ));
With Network Timeout
try {
const results = await constructorio . quizzes . getQuizResults (
'product-finder-quiz' ,
{
answers: [[ 1 , 2 ], [ 3 ]],
quizVersionId: 'abc123' ,
quizSessionId: 'session456' ,
},
{
timeout: 5000 , // 5 seconds
}
);
} catch ( error ) {
console . error ( 'Request timed out or failed:' , error );
}
Processing Results
const results = await constructorio . quizzes . getQuizResults ( 'product-finder-quiz' , {
answers: [[ 1 , 2 ], [ 3 ]],
quizVersionId: 'abc123' ,
quizSessionId: 'session456' ,
});
// Display products
results . response . results . forEach ( product => {
console . log ( 'Product:' , product . data . id );
console . log ( 'Name:' , product . value );
console . log ( 'Price:' , product . data . price );
console . log ( 'Matched terms:' , product . matched_terms );
});
// Show available facets for further filtering
results . response . facets . forEach ( facet => {
console . log ( 'Filter:' , facet . name );
console . log ( 'Options:' , facet . options );
});
// Track which quiz options were matched
results . quiz_selected_options . forEach ( option => {
if ( option . is_matched ) {
console . log ( 'Matched option:' , option . value );
}
});
Error Handling
try {
const results = await constructorio . quizzes . getQuizResults ( 'quiz-id' , {
answers: [[ 1 , 2 ], [ 3 ]],
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 === 'answers is a required parameter of type array' ) {
console . error ( 'Answers array is required' );
} else if ( error . message === 'getQuizResults response data is malformed' ) {
console . error ( 'Invalid response from server' );
} else {
console . error ( 'Request failed:' , error );
}
}
Notes
The answers parameter is required and must be a non-empty array
Always use the quiz_version_id and quiz_session_id from your initial getQuizNextQuestion call
The hiddenFields parameter is a convenience that automatically merges into fmtOptions.hidden_fields
Use pagination (page and resultsPerPage) for large result sets
The result_id should be used for tracking user interactions with results
Additional filters can be applied on top of quiz logic using the filters parameter
The response will throw an error if quiz_version_id is not present, indicating a malformed response
API Reference