Skip to main content

Using Quizzes

Work in progress

This feature is still in active development as we continue to build out increased functionality. Information here will change over time as this product continues to evolve rapidly.

Answering a Quiz

When a user is progressing through a quiz, we are using the same API, but adding additional query parameters for subsequent questions.

Answering a question
curl -X GET \
-H "Content-Type: application/json" \
"https://quizzes.cnstrc.com/v1/quizzes/[quiz_id]/next?key=[your index key]&a=[option_id_1]&a=[option_id_2]"
Sample Response
{
"next_question": {
"id": 2,
"title": "What do you want to ask",
"description": "Sample description",
"type": "multiple",
"options": [
{
"id": 1,
"value": "Who",
"attribute": {
"name": "group_id",
"value": "test-value"
}
},
{
"id": 2,
"value": "What",
"attribute": {
"name": "group_id",
"value": "test-value"
}
},
{
"id": 3,
"value": "Where",
"attribute": {
"name": "group_id",
"value": "test-value"
}
},
{
"id": 4,
"value": "When",
"attribute": {
"name": "group_id",
"value": "test-value"
}
},
{
"id": 5,
"value": "How",
"attribute": {
"name": "group_id",
"value": "test-value"
}
}
]
},
"version_id": "",
"is_last_question": false
}

HTTP request

GET https://quizzes.cnstrc.com/v1/quizzes/[quiz_id]/next?key=[your index key]&a=[option_id_1]&a=[option_id_2]

URL Parameters

AttributeTypeRequired?Description
quiz_idstringYesThe id of the quiz
keystringYesThe index key of your product catalog.
astringnoA list of answers in the format ?a=[option_id_1]&a=[option_id_2] with one a parameter for each question. The expected format for each parameter depends on the question type, as described below.

Types of questions

Single select

Single select questions are questions that only allow a single option to be selected. Available options are specified in the options attribute.

Sample Response
{
"next_question": {
"id": 1,
"title": "Sample single select question",
"description": "Sample description",
"type": "single",
"options": [
{
"id": 1,
"value": "Who",
"attribute": {
"name": "group_id",
"value": "test-value"
}
},
{
"id": 2,
"value": "What",
"attribute": {
"name": "group_id",
"value": "test-value"
}
}
]
},
"version_id": "",
"is_last_question": false
}
info

The attribute field in each option is combined at the end in a much larger filter expression to filter results for this quiz.

Multiple select

Multiple select questions are questions that allow multiple options to be selected. Available options are specified in the options attribute. Multiple options for a single answer are supplied in the same answer parameter (separated by ",").

Sample Response
{
"next_question": {
"id": 1,
"title": "Sample multiple select question",
"description": "Sample description",
"type": "multiple",
"options": [
{
"id": 1,
"value": "Who",
"attribute": {
"name": "group_id",
"value": "test-value"
}
},
{
"id": 2,
"value": "What",
"attribute": {
"name": "group_id",
"value": "test-value"
}
}
]
},
"version_id": "",
"is_last_question": false
}

Open text

Open text questions are questions that do not have any options and accepts a=true or a=false as an answer in the url query parameters. a=true denotes that the question is answered and vice versa.

true or false are the only acceptable answers for this type of question. We do not store actual text responses from any of the open-text text fields specified on the front-end of these questions.

Sample Response
{
"next_question": {
"id": 1,
"title": "Sample open text question",
"description": "Sample description",
"type": "open"
},
"version_id": "",
"is_last_question": false
}

Cover page

Cover page questions are not technically questions but they are usually used to display a cover page (a page of only content and/or imagery used to provide additional information, divide sections of a quiz, etc). A cta_text field is also provided in the response for ease of specifying content in a call to action button (usually a "next" button). To move to the next question, an a=seen query parameter should be provided.

Sample Response
{
"next_question": {
"id": 1,
"title": "Sample cover page",
"description": "Sample description",
"type": "cover",
"cta_text": "Next"
},
"version_id": "",
"is_last_question": false
}

Completing the quiz

When it's the last question, instead of sending the same API call, we would have to use another API call to finalize the entire quiz.

Finalize quiz submission
curl -X GET \
-H "Content-Type: application/json" \
"https://quizzes.cnstrc.com/v1/quizzes/[quiz_id]/finalize?key=[your index key]&a=[option_id_1]&a=[option_id_2]"
Sample Response
{
"result": {
"filter_expression": {
"and": [
{ "name": "group_id", "value": "W123456" },
{
"or": [
{ "name": "group_id", "value": "W95680" },
{ "name": "group_id", "value": "W1338473" },
{ "name": "group_id", "value": "W1349792" },
{ "name": "group_id", "value": "W162459" }
]
},
{
"or": [
{ "name": "color", "value": "Blue" },
{ "name": "color", "value": "Black" },
{ "name": "color", "value": "Grey" }
]
}
]
},
"results_url": "https://ac.cnstrc.com/recommendations/v1/strategies/filtered_items?key=xaUaZEQHQWnrNZbq&collection_filter_expression=%3D%7B%22and%22%3A%5B%7B%22name%22%3A%22group_id%22%2C%22value%22%3A%22W123456%22%7D%2C%7B%22or%22%3A%5B%7B%22name%22%3A%22color%22%2C%22value%22%3A%22Purple%22%7D%2C%7B%22name%22%3A%22color%22%2C%22value%22%3A%22Black%22%7D%2C%7B%22name%22%3A%22color%22%2C%22value%22%3A%22Blue%22%7D%5D%7D%5D%7D"
},
"version_id": "11db5ac7-67e1-4000-9000-414d8425cab3"
}

HTTP request

GET https://quizzes.cnstrc.com/v1/quizzes/[quiz_id]/finalize?key=[your index key]&a=[option_id_1]&a=[option_id_2]

URL Parameters

AttributeTypeRequired?Description
quiz_idstringYesThe id of the quiz
keystringYesThe index key of your product catalog.
astringnoA list of answers in the format ?a=[option_id_1]&a=[option_id_2] where multiple options for a single answer are supplied in the same answer parameter (separated by ",") and options for the next question are supplied in the next answer parameter.