net_backend

API reference

Examples

10. Examples: curl#

shell
API=https://your-server.example

# Server info (no auth)
curl -sS "$API/v1/info"
# {"protocol":1,"min_protocol":1,"modules":["auth","chat","files","friends","groups","leaderboards","lobbies","matchmaking","notifications","oauth","storage"]}

# Register (logs in at once)
curl -sS "$API/v1/auth/register" -H 'content-type: application/json' \
  -d '{"email":"player@example.com","password":"correct horse battery","display_name":"Player One"}'
# {"account":{"id":42,...},"tokens":{"token_type":"Bearer","access_token":"nbsa_...","access_expires_at":...,"refresh_token":"nbsr_...","refresh_expires_at":...}}

# Log in
curl -sS "$API/v1/auth/login" -H 'content-type: application/json' \
  -d '{"email":"player@example.com","password":"correct horse battery"}'

# Log in with an OpenID Connect provider's ID token (the server's `oauth` module, provider `google`)
curl -sS "$API/v1/auth/oauth/google" -H 'content-type: application/json' \
  -d '{"id_token":"eyJhbGciOiJSUzI1NiIs...","nonce":"the-nonce-of-the-sign-in"}'

ACCESS=nbsa_...    # tokens.access_token
REFRESH=nbsr_...   # tokens.refresh_token

# Who am I
curl -sS "$API/v1/account" -H "authorization: Bearer $ACCESS"

# Refresh (single use: store the new pair)
curl -sS "$API/v1/auth/refresh" -H 'content-type: application/json' \
  -d "{\"refresh_token\":\"$REFRESH\"}"

# Upload a file (multipart: the optional meta part first, then the file), download it
curl -sS "$API/v1/files" -H "authorization: Bearer $ACCESS" \
  -F 'meta={"visibility":"public"};type=application/json' -F 'file=@screenshot.png;type=image/png'
# {"id":12,"owner":42,"name":"screenshot.png","content_type":"image/png","size":48213,"sha256":"…","visibility":"public",...}
curl -sS "$API/v1/files/12/content" -H "authorization: Bearer $ACCESS" -o screenshot.png

# Save an object (create only if new)
curl -sS -X PUT "$API/v1/storage/saves/slot-1" -H "authorization: Bearer $ACCESS" \
  -H 'content-type: application/json' -d '{"value":{"level":3,"gold":250},"if_version":0}'
# {"collection":"saves","key":"slot-1","version":1,"updated_at":...}

# Load it (the ETag header is the version)
curl -sS -i "$API/v1/storage/saves/slot-1" -H "authorization: Bearer $ACCESS"

# Overwrite only version 1
curl -sS -X PUT "$API/v1/storage/saves/slot-1" -H "authorization: Bearer $ACCESS" \
  -H 'content-type: application/json' -d '{"value":{"level":4,"gold":300},"if_version":1}'
# a stale version: 409 {"error":{"code":"version_conflict","message":"...","details":{"current_version":2}}}

# List a collection (no values), then delete
curl -sS "$API/v1/storage/saves?limit=20" -H "authorization: Bearer $ACCESS"
curl -sS -X DELETE "$API/v1/storage/saves/slot-1?if_version=2" -H "authorization: Bearer $ACCESS"

# Chat over HTTP: public rooms, a room's history, open a DM
curl -sS "$API/v1/chat/rooms" -H "authorization: Bearer $ACCESS"
curl -sS "$API/v1/chat/rooms/12/messages?limit=50" -H "authorization: Bearer $ACCESS"
curl -sS "$API/v1/chat/dm" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"user":77}'
# Chat extras: edit a message, the read marker, unread counts, a player's own room
curl -sS -X PATCH "$API/v1/chat/rooms/12/messages/981" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"text":"hello again"}'
curl -sS -X PUT "$API/v1/chat/rooms/12/read" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"message":981}'
curl -sS "$API/v1/chat/unread" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"rooms":[12,13]}'
curl -sS "$API/v1/chat/rooms" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"name":"Night Owls","visibility":"public"}'
curl -sS "$API/v1/chat/rooms/40/invites" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"user":77}'

# Leaderboards (a server with the leaderboards module and a board `highscore`)
curl -sS "$API/v1/leaderboards/highscore/scores" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"score":1200}'
# {"board":"highscore","score":1200,"submitted":1200,"changed":true,"rank":3}
curl -sS "$API/v1/leaderboards/highscore?limit=10" -H "authorization: Bearer $ACCESS"
curl -sS "$API/v1/leaderboards/highscore/around?above=2&below=2" -H "authorization: Bearer $ACCESS"

# Friends: my friend code, a request by code, accept one, my friends with their online state
curl -sS "$API/v1/friends/code" -H "authorization: Bearer $ACCESS"
curl -sS "$API/v1/friends/requests" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"code":"K7M2Q9XD"}'
curl -sS -X POST "$API/v1/friends/requests/77/accept" -H "authorization: Bearer $ACCESS"
curl -sS "$API/v1/friends" -H "authorization: Bearer $ACCESS"
# Which of my Steam friends play here (a Steam-linked account), and hiding myself from that lookup
curl -sS "$API/v1/friends/steam" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"steam_ids":["76561201960265729"]}'
curl -sS -X PUT "$API/v1/friends/settings" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"steam_findable":false}'

# Groups: create one, find groups by name, invite a player, accept an invitation (as that player)
curl -sS "$API/v1/groups" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"name":"Night Owls","open":false}'
curl -sS "$API/v1/groups?query=night" -H "authorization: Bearer $ACCESS"
curl -sS "$API/v1/groups/5/invites" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"user":77}'
curl -sS -X POST "$API/v1/groups/5/invites/accept" -H "authorization: Bearer $ACCESS"

# Lobbies: create one, join another with its code, set ready, search public lobbies by metadata
curl -sS "$API/v1/lobbies" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"max_players":4,"metadata":{"mode":"ranked"}}'
curl -sS "$API/v1/lobbies/join" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"code":"K7M2-Q9XD"}'
curl -sS -X PUT "$API/v1/lobbies/7/ready" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"ready":true}'
curl -sS "$API/v1/lobbies/search" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"filters":[{"key":"mode","value":"ranked"}]}'

# Matchmaking: queue for a duel, then read the ticket (waiting, or matched with its players)
curl -sS "$API/v1/matchmaking/ticket" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"queue":"duel","attributes":{"rating":1520}}'
curl -sS "$API/v1/matchmaking/ticket" -H "authorization: Bearer $ACCESS"

# Notifications (a server with the notifications module): unread ones, mark all read
curl -sS "$API/v1/notifications?unread_only=true" -H "authorization: Bearer $ACCESS"
curl -sS "$API/v1/notifications/mark" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"all":true,"read":true}'

# Password reset (website flow)
curl -sS "$API/v1/auth/password/forgot" -H 'content-type: application/json' -d '{"email":"player@example.com"}'
curl -sS "$API/v1/auth/password/reset" -H 'content-type: application/json' \
  -d '{"token":"<token from the mail link>","new_password":"another long passphrase"}'

# Log out (this session; with an expired access token send {"refresh_token":"..."} instead)
curl -sS "$API/v1/auth/logout" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{}'

# The API documents
curl -sS "$API/v1/openapi.json" -o openapi.json
curl -sS "$API/v1/asyncapi.json" -o asyncapi.json

Generated from API.md (repository commit 84a9d3c, file sha256 e735542eb5f5).