Get App Leaderboard

get
Get App Leaderboard

https://api.bountyblok.io/v1/get_leaderboard
This endpoint allows you to retrieve the app leaderboard based on the total challenge scores. The data can be retrieved as JSON or HTML.
Request
Response
Request
Headers
Authorization
required
string
Bearer <<YOUR_API_KEY>>
Query Parameters
app_id
required
string
The app id of the app containing the ranked challenges.
limit
optional
integer
The number of users to display per page. Default: 20
offset
optional
integer
The page number to begin retrieving results. Default: 0
widget_response
optional
string
Returns the html+data if 'html' is specified. Default: 'json'
leaderboard_type
optional
string
Displays and sorts the leaderboard by 'score' or 'xp'. Default: 'score'
Response
200: OK
Leaderboard successfully retrieved. Can also return as HTML if specified in the widget_response.
{
"leaderboard_users":
[
{
"rank": 1,
"external_user": {
"username": "jeanguy"
},
"challenge_count": 1,
"task_count": 3,
"score": 100,
"total_xp": 1400
},
{
"rank": 2,
"external_user": {
"username": "user111222"
},
"challenge_count": 1,
"task_count": 1,
"score": 100,
"total_xp": 1100
},
{
"rank": 3,
"external_user": {
"username": "jimbo"
},
"challenge_count": 0,
"task_count": 0,
"score": 0,
"total_xp": 200
}
],
"total_users": 3,
"message": null,
"is_valid": true
}
404: Not Found
Could not find an app with this app_id.
{
is_valid: false,
"message": "App id not found"
}
cURL
C#
Javascript
Python
PHP
cURL
curl --request GET
--url 'https://api.bountyblok.io/v1/get_leaderboard?app_id=8a205981-61c9-4c27-bea7-ed42ab787040'
--header 'authorization: Bearer <<YOUR_API_KEY>>'
--data '{}'
C#
var client = new RestClient("https://api.bountyblok.io/v1/get_leaderboard?app_id=8a205981-61c9-4c27-bea7-ed42ab787040");
var request = new RestRequest(Method.GET);
request.AddHeader("authorization", "Bearer <<YOUR_API_KEY>>");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Javascript
var data = "{}";
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://api.bountyblok.io/v1/get_leaderboard?app_id=8a205981-61c9-4c27-bea7-ed42ab787040");
xhr.setRequestHeader("authorization", "Bearer <<YOUR_API_KEY_HERE>>");
xhr.send(data);
Python
import http.client
conn = http.client.HTTPSConnection("api.bountyblok.io")
payload = "{}"
headers = { 'authorization': "Bearer <<YOUR_API_KEY>>" }
conn.request("GET", "/v1/get_leaderboard?app_id=8a205981-61c9-4c27-bea7-ed42ab787040", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
PHP
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.bountyblok.io/v1/get_leaderboard?app_id=8a205981-61c9-4c27-bea7-ed42ab787040",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "{}",
CURLOPT_HTTPHEADER => array(
"authorization: Bearer <<YOUR_API_KEY_HERE>>"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}

HTML Leaderboard

The App Leaderboard can be retrieved in HTML by specifying &widget_response=html .

Create an empty div for the leaderboard HTML and insert the HTML:

<div id="bb-leaderboard">Loading ... </div>

XMLHttpRequest
jQuery
XMLHttpRequest
var data = "{}";
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
document.getElementById('bb-leaderboard').innerHTML = JSON.parse(this.responseText).html;
}
});
xhr.open("GET", "https://api.bountyblok.io/v1/get_leaderboard?app_id=8a205981-61c9-4c27-bea7-ed42ab787040&widget_response=html&leaderboard_type=score");
xhr.setRequestHeader("authorization", "Bearer <<YOUR_API_KEY_HERE>>");
xhr.send(data);
jQuery
var settings = {
"async": true,
"url": "https://api.bountyblok.io/v1/get_leaderboard?app_id=7e5deae7-483b-4153-931a-2fe71aa3f036&widget_response=html&leaderboard_type=score",
"method": "GET",
"headers": {
"authorization": "Bearer <<YOUR_API_KEY_HERE>>"
},
"data": "{}"
}
$.ajax(settings).done(function (response) {
$('#bb-leaderboard').html(response.html);
});