Quiz Results
/api/v1/quiz_results end points reads quiz results from cbsplit cms and sends json as output
#
Make an api request to visits endpointhttp://YOUR_CBSPLIT_HOST/api/v1/quiz_results
Every request should provide API Key via X-API-Key header.
API will return 100 results per page. Use page param for pagination.
#
ResponseAPI will return a JSON object like bellow:
{ entries: [], totalEntries: Number, page: Number, totalPages: Number }
Every entry will have the following structure:
- id: Integer
- created_at: UTC Timestamp
- quiz_id : Integer
- user_id : Integer
- score : Integer
- data : Object
{ "some question": "some answer", "another question": "another answer" }
#
API Call Rate LimitsMaximum 60 Requests Per Minute per IP Address. If limit reached 429 status code returned with an empty body.
#
Filters- id
- created_at
- quiz_id
- user_id
- score
By default any column will filter by exact value.
e.g. { "created_at": "2020-02-03T17:16:00.485Z" }
will return entries created at that exact timestamp.
To get entries created after specific time use gt/gte modifier:
{ "created_at.gt": "2020-02-03" } or { "created_at.gte": "2020-02-03" }
To get entries created before specific time use lt/lte modifier:
{ "created_at.lt": "2020-02-03" } or { "created_at.lte": "2020-02-03" }
To get entries created within specific timespan use between modifier, providing two comma separated values:
{ "created_at.between": "2020-02-03,2020-03-03" }
It's also possible to filter by multiple exact values by using in modifier and providing comma separated values:
{ "country.in": "US,CA" }
This same logic applies to all columns, except Boolean ones. To filter by Boolean columns use t for true and f for false.
{ "mobile": "t" }
or { "mobile": "f" }
#
Filter Requests Examples/api/v1/quiz_results?created_at.gt=2020-02-03/api/v1/quiz_results?created_at.between=2020-02-03,2020-03-01/api/v1/quiz_results?country.in=US,CA&mobile=t
#
Code Samples#
cURL - Command LineGet first 100 results
curl -H "X-API-Key: XXXXXXXXXXXXXXXX" https://YOUR_CBSPLIT_HOST/api/v1/quiz_results
Get next 100 results
curl -H "X-API-Key: XXXXXXXXXXXXXXXX" https://YOUR_CBSPLIT_HOST/api/v1/quiz_results?page=2
#
NodeJs Codefetch("https://YOUR_CBSPLIT_HOST/api/v1/quiz_results", { method: "get", headers: { 'X-API-Key': 'XXXXXXXXXXXXXX', 'User-Agent': 'Mozilla/5.0 (compatible; cURL/7.68.0)' }}) .then(res => res.json()) .then(data => console.log(data)) .catch(err => console.log(err))
#
PHP Code<?php
$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "https://YOUR_CBSPLIT_HOST/api/v1/quiz_results");$headers = [ 'X-API-Key: XXXXXXXXXXXXXX',];curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; cURL/7.68.0)');curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
if(curl_errno($ch)) { echo "curl error: " . curl_error($ch);} else { $data = json_decode($response, true); print_r($data);}curl_close($ch);
?>
#
Python codeimport requests
url = "https://YOUR_CBSPLIT_HOST/api/v1/quiz_results"headers = { "X-API-Key": "XXXXXXXXXXXX", "User-Agent": "Mozilla/5.0 (compatible; cURL/7.68.0)"}
response = requests.get(url, headers=headers)if response.status_code == 200: data = response.json() for obj in data['entries']: print (obj)else: print(f"Error: {response.status_code}")
#
Ruby coderequire 'net/http'require 'uri'
url = URI.parse("https://YOUR_CBSPLIT_HOST/api/v1/quiz_results")
http = Net::HTTP.new(url.host, url.port)http.use_ssl = (url.scheme == "https")
request = Net::HTTP::Get.new(url.path)request["X-API-Key"] = "xxxxxxxxxxx" # Replace with your actual API keyrequest["User-Agent"] = "Mozilla/5.0 (compatible; cURL/7.68.0)"
response = http.request(request)
puts response.body