Random dice roll API in JSON
The DéJeté API lets you add a random dice generator to a website, game, prototype or script without rebuilding a rolling interface.
The response contains the result of each die in JSON, ready to be processed by your server-side code or application.
Dice API parameters and request format
Send a GET request with the number of dice and the number of sides, as shown in the example below.
Example API call: https://www.dejete.com/api?nbde=5&tpde=6
The “nbde” parameter sets the number of dice, while “tpde” sets the number of sides on each die. This example rolls 5 six-sided dice.
Read and use the JSON roll results
The GET request returns a JSON response that you can decode and use in your script or application.
PHP integration example:
<?php
$resultat = file_get_contents('https://www.dejete.com/api?nbde=5&tpde=6');
$json = json_decode($resultat);
foreach($json as $de)
{
echo $de->id.' : '.$de->value.'<br>';
}
?>
Each result contains the JSON fields “id” and “value”: “id” identifies the die and “value” contains the random value rolled.
When should you use the DéJeté dice API?
The API works well for game prototypes, educational tools and small automations that need numeric rolls. To check the behavior visually before integrating it, first try the online dice roller or the d4 to d100 RPG dice page.