JavaScript SDK — Players

Players — mp.players

register
await mp.players.register(playerName, { playerData?, birthYear?, steamTicket?, steamIdentity?, googleAuthCode?, googleIntegrityToken?, playerToken?, restore? })

Registers a player. Returns player_id, private_key (the player token — store it) and player_tag. Steam fields accept a hex auth ticket + identity; Google Play fields accept the server auth code plus optional Play Integrity token. Pass restore only after the player explicitly confirms a deletion-restore prompt — never automatically.

login
await mp.players.login(playerToken)

Starts the player session (PUT /login).

heartbeat
await mp.players.heartbeat(playerToken)

Keeps the player marked online — call on an interval while the session is active.

logout
await mp.players.logout(playerToken)

Ends the session cleanly.

rename
await mp.players.rename(playerToken, newName)

Renames the player; the new name is validated against the game's name rules server-side.

rotate
await mp.players.rotate(playerToken)

Rotates the player credential — store the returned private_key; the old token is retired.

deleteAccount
await mp.players.deleteAccount(playerToken)

Schedules player-initiated account deletion. The account freezes immediately and is purged after the 30-day grace window unless restored. Keep the player credential during the window; the response includes deletion_pending and purge_after.

restoreAccount
await mp.players.restoreAccount(playerToken)

Cancels a pending deletion. This must be an explicit player action, never an automatic login or background retry. Provider-linked accounts can also restore after reinstall by signing in with the provider and restore: true after confirmation.

list (admin)
await mp.players.list()

Lists all players. Requires apiPrivateToken — server-side only.

ban / unban (admin)
await mp.players.ban(playerId, { banDuration?, banReason? })
await mp.players.unban(playerId)

Timed or permanent bans. Admin operations — never ship the private token in a client.

getData / updateData
await mp.players.getData(playerToken)
await mp.players.updateData(playerToken, playerData)

Per-player JSON storage — stats, loadouts, progression. Leaderboards rank these fields server-side.

Sessions, tokens and name rules

Register creates the player and returns the token your game stores and presents as X-Game-Player-Token. Login re-opens the session on a later run; heartbeat keeps the player marked online while they play; logout ends the session cleanly. Rotate issues a fresh credential and invalidates the old one — call it any time a token may have leaked.

Registration and rename validate the display name server-side against your game's name rules — allowed scripts, case policy and symbols, edited in the cabinet — plus the profanity screen. A rejected name comes back as a fielded error you can show the player instead of guessing why it failed.

  • Players register with just a display name — identity is the returned token, so store it like a credential.
  • Admin calls — list, ban and unban — use the API token pair. Never ship the private token in a client build.
  • Each player also carries a JSON data record — stats, loadouts, progression — that leaderboards rank server-side.
  • Every call returns a Promise — await inside async functions. In browsers requests run over fetch with CORS; on Node.js 22.12+ the identical API uses the built-in fetch.