Skip to content

Initialize Quiz ​

Initialize a quiz for a user and generate an empty answer object.


Overview ​

This endpoint creates an empty quiz answer object for the user and must be called before submitting any answers. The endpoint varies based on the quiz type.

Method: POST

Endpoints by Quiz Type ​

Quiz TypeEndpoint
Anonymous/api/v1/namespaces/:namespaceId/quizzes/:quizId/users/anonymous/initQuiz
In-App/api/v1/namespaces/:namespaceId/quizzes/:quizId/users/inapp/:sessionId/initQuiz
Invited/api/v1/namespaces/:namespaceId/quizzes/:quizId/users/invited/:invitedUserUUID/initQuiz

See Quiz Types to understand the differences between anonymous, in-app, and invited quizzes.


Request ​

Path Parameters ​

ParameterTypeRequiredQuiz TypeDescription
namespaceIdstring✅AllNamespace unique ID
quizIdstring✅AllQuiz unique ID
sessionIdstring✅In-AppIn-app session identifier
invitedUserUUIDstring✅InvitedInvited user unique ID

Body Parameters ​

FieldTypeRequiredQuiz TypeDescription
anonymousUserIdstring✅AnonymousAnonymous user identifier (from Generate Anonymous User ID)
languagestring✅AllLanguage code for questions (en for English, es for Spanish)
customParamsstring❌AllOptional custom parameters, useful for tracking UTM tags or any custom data

Example Request Bodies ​

json
{
  "anonymousUserId": "anon_12345ABC",
  "language": "en",
  "customParams": "utm_source=newsletter"
}
json
{
  "language": "en",
  "customParams": "utm_source=app"
}
json
{
  "language": "en",
  "customParams": "utm_source=email"
}

Response ​

Example Responses ​

json
{
  "answers": {
    "id": "12345ABCD-anon1234",
    "userId": "anon1234",
    "quizId": "abc12345",
    "activityDate": {
      "_seconds": 1768503849,
      "_nanoseconds": 805000000
    },
    "qAnswers": {},
    "completionStatus": 1,
    "isAnonymous": true,
    "customData": ""
  },
  "anonymousUserId": "anon_12345ABC"
}
json
{
  "answers": {
    "id": "quizid1234-session1234",
    "userId": "session1234",
    "quizId": "quizid1234",
    "activityDate": {
      "_seconds": 1768504063,
      "_nanoseconds": 907000000
    },
    "qAnswers": {},
    "completionStatus": 1,
    "isAnonymous": false,
    "customData": ""
  }
}
json
{
  "answers": {
    "id": "12345ABCD-user1234",
    "userId": "user1234",
    "quizId": "abc12345",
    "activityDate": {
      "_seconds": 1768504488,
      "_nanoseconds": 170000000
    },
    "qAnswers": {},
    "completionStatus": 1,
    "isAnonymous": false,
    "customData": ""
  }
}

Response Fields ​

FieldTypeDescription
idstringUnique answer document ID (format: quizId-userId)
userIdstringUser identifier
quizIdstringQuiz identifier
activityDateobjectTimestamp of initialization
qAnswersobjectEmpty object (no answers submitted yet)
completionStatusnumber1 = initialized, 2 = in progress, 3 = completed
isAnonymousbooleantrue for anonymous quizzes, false for invited and in-app
customDatastringCustom data stored with the response
anonymousUserIdstringReturned only for anonymous quizzes

Error Responses ​

  • 400 Bad Request – If the namespace has reached its response limit
json
{
  "error": "Limit of responses reached!"
}
  • 400 Bad Request – If the quiz has ended
json
{
  "error": "quiz has ended",
  "errorCode": "quiz/ended"
}
  • 400 Bad Request – If the quiz type doesn't match the endpoint (e.g., using anonymous endpoint for non-anonymous quiz)
json
{
  "error": "quiz only takes non anonymous submissions",
  "errorCode": "quiz/not_anonymous"
}
  • 404 Not Found – If the namespace does not exist
json
{
  "error": "namespace not found",
  "errorCode": "namespace/not_found"
}
  • 404 Not Found – If the quiz does not exist
json
{
  "error": "quiz not found",
  "errorCode": "quiz/not_found"
}
  • 404 Not Found – If the invited user does not exist (for invited quizzes)
json
{
  "error": "user does not exist",
  "errorCode": "users/not_found"
}
  • 403 Forbidden – If the invited user is not part of the quiz (for invited quizzes)
json
{
  "error": "user is not part of the quiz",
  "errorCode": "users/unauthorized"
}
  • 422 Unprocessable Entity – If required parameters are missing or validation fails
json
{
  "validationErrors": {
    "body": {
      "language": {
        "message": "\"language\" is required"
      }
    }
  }
}