Facebook Instant Games

QuestEngine is a ready-made backend for HTML5 games on Facebook and Messenger. It covers sign-in that works with Zero Permissions, daily challenges with streaks, async duels you share in a chat, friend leaderboards from connected players, and Meta's data deletion requirements. It has the same player accounts, economy and live ops as mobile games, with no server of your own to run.

This guide follows the order of calls an Instant Game makes. The API reference has every field.

Before you start

  1. Add the game in the console, then open Game settings → Player accounts:
    • tick Facebook Instant Games under sign-in methods;
    • under Facebook, enter the App ID and paste the App secret (it is stored encrypted and never shown again);
    • under Web games, tick Daily challenges and/or Async duels;
    • set Delete inactive players after to the period your privacy policy promises, for example 183 days.
  2. Allow the API host in your game's network settings if you restrict them: https://questengine.eu.
  3. Every call sends the game's public client key, X-Game-Key: qe_pk_… (console: API & SDKs). Player calls also send Authorization: Bearer <token>.

Daily challenges and duels also need the web-games features switched on for the QuestEngine server: QE_WEB_GAMES and the QE_FEATURE_* flags.

1. Sign in

Instant Games have no Facebook Login. The player is identified by a signature Meta makes with your app secret:

await FBInstant.initializeAsync();
const nonce = crypto.randomUUID();
const signed = await FBInstant.player.getSignedPlayerInfoAsync(nonce);
let signedAsid = null;
try { signedAsid = (await FBInstant.player.getSignedASIDAsync())?.getSignature() ?? null; } catch {}

const res = await fetch('https://questengine.eu/api/v1/auth/facebook-instant', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', 'X-Game-Key': CLIENT_KEY },
  body: JSON.stringify({
    signature: signed.getSignature(),
    request_payload: nonce,
    signed_asid: signedAsid,            // leave out when there is none
    display_name: FBInstant.player.getName(),
    platform: 'facebook_instant',
    locale: FBInstant.getLocale(),
  }),
});
const { data } = await res.json();     // data.token, data.player.id, data.player.instant_player_id

2. Friends from connected players

Under Zero Permissions there is no friends list and no access token, but getConnectedPlayersAsync() works. Send those IDs after sign-in and whenever you refresh them:

const connected = await FBInstant.player.getConnectedPlayersAsync();
await api('POST', '/friends/facebook-instant', { player_ids: connected.map(p => p.getID()).slice(0, 200) });
// → { connected: 2, players: [{ id, display_name, instant_player_id, … }] }

3. Leaderboards

Create boards in the console (Leaderboards). Set the lowest and highest accepted score, because these scores come from the game.

await api('POST', '/leaderboards/daily/scores', { score: 1240 });
const world = await api('GET', '/leaderboards/daily');            // public: id and display_name only
const friends = await api('GET', '/leaderboards/daily/friends');  // you + friends + connected players
const me = await api('GET', '/leaderboards/daily/me?range=5');    // your rank and neighbours

On /friends and /me, every player also has instant_player_id for you, your friends and connected players (null for others). Use it to highlight "You" and friends. World boards never show Instant IDs.

4. Daily challenges

Create a channel in the console (Live ops → Daily challenges). Everyone gets the same seed, or the same questions, each day:

const day = await api('GET', '/daily/huddle');
// day.period_key "2026-11-20", day.seed, day.items (server-scored channels), day.streak, day.submitted
// … build the puzzle from day.seed and play …
await api('POST', '/daily/huddle/results', { period_key: day.period_key, score: 1240, duration_ms: 48000 });

5. Async duels

Import a question pack in the console (Live ops → Question packs). Packs are versioned JSON:

{ "code": "spar-en-general", "name": "General knowledge", "version": "v1", "locale": "en",
  "round_count": 5, "time_limit_ms": 12000, "scoring": "authoritative",
  "items": [{ "id": "q1", "prompt": "…", "choices": ["…", "…", "…", "…"], "correct": 2 }] }

Challenging someone. Pick one of:

const duel = await api('POST', '/duels', { content_pack: 'spar-en-general', context_id: FBInstant.context.getID() });
// share duel.invite_code with FBInstant.shareAsync / updateAsync; the challenger plays right away:
await api('POST', `/duels/${duel.id}/submit`, { answers: [{ id: 'q7', choice: 2, time_ms: 3400 }, /* … */] });

// the friend opens the link:
const found = await api('GET', `/duels/invite/${code}`);
await api('POST', `/duels/${found.id}/accept`);
await api('POST', `/duels/${found.id}/submit`, { answers: [/* … */] });
// → status "completed", winner_player_id, scores

How a duel runs:

6. Data deletion

Meta requires a way for players to delete their data. QuestEngine gives you three:

  1. In the game. Add a Delete my data button that calls DELETE /me with { "confirm": true }. The player and their data are deleted at once.
  2. Meta's Data Deletion Callback. In the App Dashboard, open Settings → Basic → User data deletion and set the callback URL:
    https://questengine.eu/api/v1/facebook/data-deletion/<your app ID>
    
    When someone removes your game from Facebook, Meta posts a signed request. QuestEngine verifies it with your app secret, deletes the matching players and answers with a confirmation code and a status page. Meta names people by their app-scoped ID (ASID), so this finds only players whose game sent signed_asid at sign-in. Meta doesn't give every Instant Games player one, which is why the in-game button matters.
  3. The console. Players → Delete player, for requests that reach you by email.

All three delete the same things: progress, scores, streaks, duels, saves and friends. Purchases are kept without the link to the player for seven years, because accounting law requires it. Players who stop playing are deleted automatically after the period set in Game settings.

Errors

Every error has the same shape: { "error": { "code": "…", "message": "…", "details": { … } } }. Codes you'll meet in Instant Games:

Code Meaning
invalid_signature, signature_expired, signature_replayed Get a fresh getSignedPlayerInfoAsync() and sign in again
feature_disabled Daily challenges or duels aren't on for this game or server
round_not_started, too_fast, timing_implausible Daily or duel timing checks (see above)
period_closed That day no longer takes results
duel_expired, duel_not_in_progress, already_submitted The duel moved on; reload it
rate_limited Slow down, then retry after a moment

Next: the API reference for every endpoint and field, and the SDK guides if you also ship to mobile.