2bttns
  • Getting Started
    • What is 2bttns?
    • Quick Start
    • 🆕You Asked We Listened
  • HOW TO
    • Set up your Console
    • Use the API
    • Build a game
    • Manage game data
    • Integrate game via API
    • Retrieve scores via API
  • References
    • APIs
      • Authentication
      • Generate Game URL
      • Games
      • Game Objects
      • Tags
      • Players
      • Admin
      • Export/Import
    • Command Line Interface (CLI)
      • Install
      • Usage
      • Configuration
  • TUTORIALS
    • ✨Personalize profiles with 2bttns and Next.js
Powered by GitBook
On this page

Was this helpful?

  1. HOW TO

Integrate game via API

Generate a URL to redirect users to a unique game instance

PreviousManage game dataNextRetrieve scores via API

Last updated 1 year ago

Was this helpful?

Make sure you generate a Bearer Token to authenticate your API requests to the Console!

Use the API to generate a unique game instance. Send users to this URL to play your game and collect data.

Generate a unique game URL

To generate a secure game instance URL for your user to play a game, use the /api/authentication/generatePlayUrl endpoint and specify the app_id, secret, game_id, the player_id, num_items, and callback_url.

Find game_id in Console

We can get the game_id from our Console by navigating to Games:

Example

Example fetch request
let fetch;
(async () => {
    fetch = (await import('node-fetch')).default;

    const url = 'http://localhost:3262';
    const endpoint = '/api/authentication/generatePlayURL';
    const params = {
        app_id: "example-app", // Use environment variables as needed
        secret: "example-secret-value",
        game_id: "booksort",
        player_id: "a-user-id",
        callback_url: "https://www.example.com",
        num_items: 5 // num_items will override Round Length set in your Console
    };

    try {
        const response = await fetch(`${url + endpoint}?app_id=${params.app_id}&secret=${encodeURIComponent(params.secret)}&game_id=${params.game_id}&player_id=${params.player_id}&callback_url=${encodeURIComponent(params.callback_url)}`, {
            method: 'GET',
            headers: {
                'Authorization': `Bearer ${BearerToken}` 
            }
        });
        const url = await response.json();
        console.log(url);
    } catch (error) {
        console.error('Error:', error);
    }
})();

Console > Games

Generate play URL

get

Returns a URL you can use to send a user to play a game in 2bttns.

Authorizations
Query parameters
app_idstringRequired

ID of the app you've created in 2bttns

secretstringRequired

Secret of the app you've created in 2bttns

game_idstringRequired

ID of the game you want to play in 2bttns

player_idstringRequired

ID of the player you want to play in 2bttns. If the player doesn't already exist, it will be created.

num_itemsstringOptional
callback_urlstringOptional
expires_instringOptional
Responses
200
Successful response
application/json
Responsestring
default
Error response
application/json
get
GET /api/authentication/generatePlayURL?app_id=text&secret=text&game_id=text&player_id=text HTTP/1.1
Host: 
Authorization: Bearer YOUR_SECRET_TOKEN
Accept: */*
text
  • Generate a unique game URL
  • GETGenerate play URL
  • Find game_id in Console
  • Example