# Quiz

## Quiz List

<mark style="color:blue;">`GET`</mark> `‎https://<domain>/<api prefix>/<version>/quiz/list/`

This API endpoint will return a list of the available quiz.

#### Query Parameters

| Name   | Type   | Description |
| ------ | ------ | ----------- |
| limit  | string |             |
| offset | string |             |
| name   | string | Quiz name   |

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string | Apikey              |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer access token |

{% tabs %}
{% tab title="200 " %}

```markup
HTTP/1.1 200 OK
Content-Type: application/json

Body:
{
    "status_code": 200,
    "errors": {},
    "data": {
        "results": [
            {
                "slug": "<quiz_slug>",
                "name": "<quiz_name>",
                "question_count": <question_count>,
                "description": "<description>",
                "quiz_details": {
                    "name": "<name>",
                    "maximum_questions": <maximum_questions>,
                    "quiz_duration": "<quiz_duration>",
                    "total_score": <total_score>,
                    "badge": "<badge>",
                    "description": "<description>",
                    "rules": "<rules>"
                }
            }
            ...
        ],
        "count": <list_count>,
        "previous": <previous_page_url>,
        "next": <next_page_url>
    }
}
```

{% endtab %}
{% endtabs %}

#### Sample Code

**Node**

```javascript
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://<domain>/<api prefix>/<version>/quiz/list/',
  'headers': {
    'apikey': '<apikey>',
    'Authorization': 'Bearer <access token>',
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

```

**PHP**

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://<domain>/<api prefix>/<version>/quiz/list/',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'apikey: <apikey>',
    'Authorization: Bearer <access token>',
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

## Quiz Summary List

<mark style="color:blue;">`GET`</mark> `‎https://<domain>/<api prefix>/<version>/quiz/list/results/`

This API endpoint will return a list of quiz summary list with details.

#### Query Parameters

| Name   | Type   | Description |
| ------ | ------ | ----------- |
| name   | string | Quiz name   |
| offset | string |             |
| limit  | string |             |

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string | Apikey              |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer access token |

{% tabs %}
{% tab title="200 " %}

```markup
HTTP/1.1 200 OK
Content-Type: application/json

Body:
{
    "status_code": 200,
    "errors": {},
    "data": {
        "results": [
            {
                "score": <score>,
                "total_score": <total_score>,
                "reward": <reward>,
                "last_attempt": "<last_attempt>",
                "attempts": <attempts>,
                "name": "<name>",
                "status": "<status>",
                "badge": {
                    "name": "<badg-name>",
                    "image": "<image>",
                    "slug": "<slug>"
                },
                "related_courses": [
                    {
                        "id": <id>,
                        "slug": "<slug>",
                        "title": "<title>",
                        "thumbnail": "<thumbnail>",
                        "short_description": "<short_description>",
                        "long_description": "<long_description>",
                        "detail_url": "<detail_url>",
                        "authors": [
                            {
                                "name": "<author_name>"
                            }
                        ],
                        "duration": "<duration>",
                        "progress": <progress>,
                        "skills": [
                            "<skills>"
                        ],
                        "price": <price>,
                        "converted_price": "<converted_price>",
                        "course_type": "<course_type>",
                        "total_reviews": "<total_reviews>"
                    },
                    ...
                ]
            },
            ...
        ],
        "count": <list_count>,
        "previous": <previous_page_url>,
        "next": <next_page_url>
    }
}
```

{% endtab %}
{% endtabs %}

#### Sample Code

**Node**

```javascript
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://<domain>/<api prefix>/<version>/quiz/list/results/',
  'headers': {
    'apikey': '<apikey>',
    'Authorization': 'Bearer <access token>',
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

```

**PHP**

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://<domain>/<api prefix>/<version>/quiz/list/results/',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'apikey: <apikey>',
    'Authorization: Bearer <access token>',
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

## Start Quiz

<mark style="color:blue;">`GET`</mark> `‎https://<domain>/<api prefix>/<version>/quiz/start/`

This API endpoint will start a quiz and return all the questions and options of the quiz.

#### Query Parameters

| Name                                   | Type   | Description |
| -------------------------------------- | ------ | ----------- |
| slug<mark style="color:red;">\*</mark> | string | Quiz slug   |

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string | Apikey              |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer access token |

{% tabs %}
{% tab title="200 " %}

```markup
HTTP/1.1 200 OK
Content-Type: application/json

Body:
{
    "status_code": 200,
    "errors": {},
    "data": {
        "questions": [
            {
                "id": <question_id>,
                "number": <question_number>,
                "question": "<question>",
                "score": <score>,
                "duration": "<duration>",
                "options": [
                    {
                        "number": <option_number>,
                        "question": <question_id>,
                        "option": "<option>",
                        "answer": <is_option>
                    },
                    ...
                ]
            },
            ...
        ]
    }
}
```

{% endtab %}
{% endtabs %}

#### Sample Code

**Node**

```javascript
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://<domain>/<api prefix>/<version>/quiz/start/',
  'headers': {
    'apikey': '<apikey>',
    'Authorization': 'Bearer <access token>',
  },
  formData: {}
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});
});

```

**PHP**

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://<domain>/<api prefix>/<version>/quiz/start/',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'apikey: <apikey>',
    'Authorization: Bearer <access token>',
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

#### Error Responses

| Status Code | Error Type       | FIeld | Description                                                                            |
| ----------- | ---------------- | ----- | -------------------------------------------------------------------------------------- |
| 400         | Validation Error | slug  | <p>Requested quiz not found.</p><p>This field is required and it may not be blank.</p> |

## Submit Answer

<mark style="color:green;">`POST`</mark> `‎https://<domain>/<api prefix>/<version>/quiz/submit/answer/`

This API endpoint will submit answer options of all quiz questions and end the quiz.

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string | Apikey              |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer access token |

#### Request Body

| Name                                      | Type   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ----------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| slug<mark style="color:red;">\*</mark>    | string | Course Slug                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| options<mark style="color:red;">\*</mark> | String | <p>Options - an array of selected options of each question,  the selected option must contain following key as per the following structure,</p><p> <strong>{ "id": \<option\_</strong><em><strong>id>, "number": \<option\_number>, "question": \<questionid>, "option": "\<option>", "answer": \<falseortrue> }</strong>, if any question is skipped or time out just add an additional key "func" with any option of corresponding question, and set the value for <strong>"func":"skip"</strong> (if question is skipped) or <strong>"func":"time\_</strong></em><strong>out"</strong> (if question time out) </p><p></p> |

{% tabs %}
{% tab title="200 " %}

```html
HTTP/1.1 200 OK
Content-Type: application/json

Body:
{
    "status_code": 200,
    "errors": {},
    "data": {}
}
```

{% endtab %}
{% endtabs %}

#### Sample Code

**Node**

```php
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://<domain>/<api prefix>/<version>/quiz/submit/answer/',
  'headers': {
    'apikey': '<apikey>',
    'Authorization': 'Bearer <access token>',

  },
  body: JSON.stringify({"slug":"<course_slug>","options":[
  {"id":<option_id>,"number":<option_number>,"question":<question_number>,"option":"<option>","answer":<answer>},...
  ]})

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});


```

**PHP**

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://<domain>/<api prefix>/<version>/quiz/submit/answer/',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "slug": "<course_slug>",
    "options":[
        {
            "id": <option_id>,
            "number": <option_number>,
            "question": <question_number>,
            "option": "<option>",
            "answer": <answer>,
        },
        ...
    ]
}',
  CURLOPT_HTTPHEADER => array(
    'apikey: <apikey>',
    'Authorization: Bearer <access token>',
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

#### Error Responses

| Status Code | Error Type       | FIeld | Description                                                                            |
| ----------- | ---------------- | ----- | -------------------------------------------------------------------------------------- |
| 400         | Validation Error | slug  | <p>This field is required and it may not be blank.</p><p>Requested quiz not found.</p> |

#### &#x20;
