Players API
Create and update players, read them back, and issue the tokens your game client needs, with the server API.
On this page
A player is someone who plays your game. Most games identify players by their own user id: GameCoin accepts it as ext:<your id> and creates the player the first time you write to it, so there is nothing to register in advance. A player id is the {player} of every path in this reference: see Referencing a player. The examples on this page continue from the setup.
Creates the ext: player if it does not exist, otherwise updates the profile fields you send. Use it when a player signs up or changes their profile; you do not need it before a grant, a spend or a checkout, which create the player themselves.
/api/v1/players/{player}- Authenticationsecret key
- Idempotencynot needed: sending the same profile twice gives the same result
Parameters
| Parameter | Type | Description |
|---|---|---|
player | string | A GameCoin player id, or ext:<your id> URL-encoded once. A GameCoin id that does not exist answers 404. |
Request body
(JSON; every field is optional, and an empty body means {})
| Field | Type | Required | Rules |
|---|---|---|---|
displayName | string or null | no | Name shown in your game: 1 to 80 characters once trimmed. null clears it. |
email | string or null | no | A valid e-mail address of at most 254 characters. Stored, never returned by the API. null clears it. |
country | string or null | no | ISO 3166-1 alpha-2 code such as BE: two letters, upper-cased for you. It is the default country of the player's checkouts. null clears it. |
birthYear | integer or null | no | A whole year between 1900 and the current year. Stored, never returned by the API. null clears it. |
A field you leave out keeps its value; null erases it. Any other field is refused.
Response
200 OK: a Player. The status is 200 whether the player was created or updated.
Errors
| Status | Code | When | What to do |
|---|---|---|---|
| 400 | VALIDATION_FAILED | An unknown field; displayName empty or longer than 80 characters; email not an address; country not two letters; birthYear not a whole year in range; a player reference that is neither a GameCoin id nor an ext: reference (PLAYER_REF_INVALID); your own id empty, longer than 128 characters or with leading or trailing whitespace | Read details.fieldErrors, fix the field. |
| 404 | NOT_FOUND | A GameCoin id that does not exist | Use ext:<your id>, which is created on the fly, or an id you got from GameCoin. |
Notes
- It is an upsert: the first call creates the player, later calls change the fields you send. To create a player with no profile, send
{}or nothing. - To erase a field, send it as
null:{"displayName": null}. An empty string is refused, not treated asnull. countryis not checked against the list of countries. Checkouts only sell to European Union countries; a player with another country gets the default countryBEunless you passcountryto Order a currency pack.- The
ext:id of a player is permanent: it is the key you will use in every later call.
Returns one player. Use it to look a player up by your own id or by GameCoin id, and to check whether they are blocked.
/api/v1/players/{player}- Authenticationsecret key
- Idempotencynot needed
Parameters
| Parameter | Type | Description |
|---|---|---|
player | string | A GameCoin player id, or ext:<your id> URL-encoded once. |
Response
200 OK: a Player.
Errors
| Status | Code | When | What to do |
|---|---|---|---|
| 400 | VALIDATION_FAILED | The reference is neither a 24-character hexadecimal id nor an ext: reference, or it was URL-encoded twice (PLAYER_REF_INVALID) | Encode the ext: reference exactly once. |
| 404 | NOT_FOUND | The player does not exist | For an ext: player this is normal until your first write: create it with Create or update a player. |
Notes
- A read never creates a player. Only writes do.
- The same player by its GameCoin id (the
idof the response) gives the same answer:
Issues a token that lets one player act on their own wallet and inventory from a browser or a game client, through the client API. Your backend calls it after it has authenticated the player, and hands the token to the client.
/api/v1/players/{player}/tokens- Authenticationsecret key
- Idempotencynot needed: every call issues a new token
Request body
none.
Parameters
| Parameter | Type | Description |
|---|---|---|
player | string | A GameCoin player id, or ext:<your id> URL-encoded once. An unknown ext: player is created. |
Response
200 OK: the token and its expiry.
| Field | Type | Description |
|---|---|---|
token | string | The player token, gc_pt_…. An opaque string: do not parse it. |
expiresAt | string | ISO 8601 date, one hour after issue. |
Errors
| Status | Code | When | What to do |
|---|---|---|---|
| 400 | VALIDATION_FAILED | The player reference is malformed (PLAYER_REF_INVALID) | Encode the ext: reference exactly once. |
| 403 | PLAYER_BLOCKED | The player is blocked | Do not hand out a token to this player. |
| 404 | NOT_FOUND | A GameCoin id that does not exist | Use an existing id, or ext:<your id>. |
Notes
- The token is tied to one player, one game and one environment: it is refused on any other. It lasts one hour: issue a new one when it expires, or when the client gets a
401. - The client sends it as
Authorization: Bearer gc_pt_…next to the publishable key, or gives it to the browser SDK asplayerToken. See Players and tokens. - A token is a credential for that player: do not log it, and send it only over HTTPS. Issuing a new one does not revoke the previous ones, which stay valid until they expire.