API Integration

Latest API version: 1.2.2

Game

CloudArcade API integration for HTML5 games. With game API, you can submit player score and show leaderboard.

Note: Game API won't work with sub-folder installation, since it's referring script from root ("/"), you need to modify script source. Also game API only work with self-hosted games (upload).

Important: If you change or edit game slug, make sure you're also change game folder name same as slug name, or API can't detect current game.

What you can do with game API ?

  • Submit player score
  • Get current player info (logged-in)
  • Show or fetch leaderboard data
  • Show Ads. more info about show ad

Let's get started.

First step.

Make sure you're using the latest version of CloudArcade.

Put <script type="text/javascript" src="/js/api.js"></script> within the <head> section of your index.html (game file).

Then open your browser console log to check if the API is loaded.

Sample code:

Submit score

You can submit a score by calling ca_api.submit_score(1000);. submit score is also an async function, so you can put "await" on it and do something after the score is already submitted to your server.

Get player/user

Once you calling ca_api.get_current_user();. You can get or access logged-in player data with ca_api.current_user;, the value is similar to parsed "data" variable.

Leaderboard

ca_api.get_scoreboard(conf); have 2 type of parameters as object {type: "top", amount: 10}, amount is how much you want to fetch score data.

Leaderboard "type":
  • "top" = The top or best score of the current game
  • "top-day" = The top or best score of the current game of the day
  • "top-week" = The top or best score of the current game of the week
  • "top-month" = The top or best score of the current game of the month
  • "top-all" = The top or best score from all games
  • "top-all-day" = The top or best score from all games of the day
  • "top-all-week" = The top or best score from all games of the week
  • "top-all-month" = The top or best score from all games of the month

Sample Projects

You can download sample project with integrated API below.

.

.

You can upload it with "Upload game" section on you admin area.


.