S&box Wiki

Revision Difference

Backend_API#545992

<cat>Dev.Backend</cat> <warning>This API is prone to changes at any time - and therefore this guide might go out of date. If something doesn't line up, it probably means the API was changed and that this page needs updating.</warning> This page is an analysis of the API used for the [dev site](https://sbox.facepunch.com/dev/) and the in-game menus; please be aware that this may change at any time and that none of this information is official. All endpoints are on the `https://apix.facepunch.com/api/` domain. To access the API, your requests **require** a header of `X-Api-Version` followed by the current version of the game (e.g. `'X-Api-Version':'25'`). # Types NOTE: Nullable types are suffixed with `?`. This API is subject to change and probably will do so before release. ## PackageType An enum specifying the different package types. Starting at 1: |Index |Name | |------|----------| | 1 | Map | | 2 | Gamemode | ## DownloadInfo An object containing a package's download type (where it's hosted, i.e. `github`), and the URL to access it. The `crc` and `size` properties are only available for `upload` types. |Name |Type |Description | |---------------|----------------|----------------------------------------------| | type | `string` | The download type of the package | | url | `string` | Download URL of the package | | crc | `uint?` | Cyclic redundancy check code | | size | `int?` | Size of the download in bytes | ⤶ ## FindResult⤶ ⤶ <removed> This Endpoint has been removed or hidden from external use </removed> ⤶ This is returned by `/sbox/asset/find` and is used to enumerate search results.⤶ ⤶ |Name |Type |Description |⤶ |---------------|-----------------|----------------------------------------------|⤶ | type | `PackageType` | The package types being returned |⤶ | assets | `MenuPackage[]` | A list of matching packages |⤶ ⤶ ## Asset⤶ ⤶ ⤶ ## Asset⤶ This is returned by `/sbox/asset/get`. |Name |Type |Description | |---------------|-----------|----------------------------------------------| | asset | `Package` | This asset's package info | ## Package These are used in various places and are used to describe assets like gamemodes and maps. |Name |Type |Description | |---------------|-------------------|-------------------------------------------------------| | org | `Org` | The organisation owning this package | | ident | `string` | This package's identifier | | title | `string` | This package's human-friendly name | | summary | `string?` | A short description for this package | | thumb | `string?` | A URL to this package's thumbnail | | packageType | `PackageType` | The package's type | | updated | `long` | UNIX timestamp for when the package was last updated | | description | `string?` | A longer description for this package | | background | `string?` | A URL to this package's in-game background | | download | `DownloadInfo` | Download information for this package | | config | `Config?` | Map & player count config for this package | | usersNow | `int` | Number of users currently playing | | usersMonth | `int` | Number of users that played this month | | usersTotal | `int` | Number of users that have ever played | | tags | `string[]` | A list of tags that describe this gamemode. | ## MenuPackage These are used in the menu (search, "trending", etc) to show a package without loading all of its data. |Name |Type |Description | |---------------|-------------------|-------------------------------------------------------| | org | `Org` | The organisation owning this package | | ident | `string` | This package's identifier | | title | `string` | This package's human-friendly name | | summary | `string?` | A short description for this package | | thumb | `string?` | A URL to this package's thumbnail | | packageType | `PackageType` | The package's type | | updated | `long` | UNIX timestamp for when the package was last updated | | usersNow | `int` | Number of users currently playing | | usersMonth | `int` | Number of users that played this month | | usersTotal | `int` | Number of users that have ever played | | tags | `string[]` | A list of tags that describe this gamemode. | ## Org These are used in various places and are used to describe organisations. |Name |Type |Description | |---------------|----------|----------------------------------------------| | ident | `string` | This organisation's identifier | | title | `string` | This organisation's human-friendly name | | description | `string?`| This organisation's description | | thumb | `string?`| A URL to the organisation's chosen thumbnail | | socialTwitter | `string?`| A URL to the organisation's Twitter account | | socialWeb | `string?`| A URL to the organisation's website | ## Config These are used to provide the game with info about how a gamemode should be set up. |Name |Type |Description | |----------------------|----------|----------------------------------------------| | showMapSelect | `bool` | Show the map select screen? | | defaultMap | `string` | Default map | | minPlayers | `int` | Minimum number of maxplayers | | maxPlayers | `int` | Maximum number of maxplayers | | clientDownloadShared | `bool` | Client downloads gamemode? | # Endpoints ## GET /sbox/asset/get ### Params `id`: An identifier (`org`.`package`) for the asset you wish to retrieve info about. ### Returns An `Asset` ### Example Request [/sbox/asset/get?id=facepunch.pool](https://apix.facepunch.com/api/sbox/asset/get?id=facepunch.pool) ### Example Response ``` { "asset": { "org": { "ident": "facepunch", "title": "Facepunch", "description": "", "thumb": "https://files.facepunch.com/sbox/org/facepunch/logo.1.png", "socialTwitter": "", "socialWeb": "" }, "ident": "pool", "title": "Pool", "summary": "A classic pub game where your skill is determined by your blood-alcohol content.\r\n", "description": "A classic pub game where your skill is determined by your blood-alcohol content.\r\n", "thumb": "https://files.facepunch.com/sbox/org/facepunch/pool/thumb.b52e5af8.jpg", "background": "https://files.facepunch.com/sbox/org/facepunch/pool/background.21884981.jpg", "packageType": 2, "updated": 1619706156, "download": { "type": "github", "url": "https://github.com/Facepunch/sbox-pool/tree/master" }, "config": { "showMapSelect": false, "defaultMap": "pool_lounge_v2", "minPlayers": 2, "maxPlayers": 2, "clientDownloadShared": true }, "usersNow": 0, "usersDay": 3, "usersMonth": 70, "usersTotal": 235, "tags": [ "!mousekeyboard", "multiplayer", "mousekeyboard" ] } } ``` --- ⤶ ## GET /sbox/asset/find⤶ ⤶ ⤶ ## GET /sbox/asset/list⤶ ### Params `type`: `map` or `gamemode`. ⤶ `order`: `trending`, `popular`, `newest`. Defaults to `trending`.⤶ ⤶ ### Returns⤶ ⤶ A `FindResult` object.⤶ ⤶ ### Example Request ⤶ ⤶ [/sbox/asset/find?type=map](http://apix.facepunch.com/api/sbox/asset/find?type=map)⤶ ⤶ ### Example Response⤶ ⤶ ```⤶ {⤶ "type": 1,⤶ "order": "Newest",⤶ "assets": [⤶ {⤶ "org": {⤶ "ident": "willow",⤶ "title": "The Willow Tree"⤶ },⤶ "ident": "castlewhitespire",⤶ "title": "Castle Whitespire",⤶ "summary": "",⤶ "thumb": "https://files.facepunch.com/sbox/org/willow/castlewhitespire/thumb.ae38aca6.jpg",⤶ "packageType": 1,⤶ "updated": 1626638355,⤶ "usersNow": 0,⤶ "usersDay": 3,⤶ "usersMonth": 3,⤶ "usersTotal": 3,⤶ "tags": []⤶ },⤶ {⤶ "org": {⤶ "ident": "kote",⤶ "title": "KotE"⤶ },⤶ "ident": "vice_city",⤶ "title": "Vice City",⤶ "summary": "Vice City",⤶ "thumb": "https://files.facepunch.com/sbox/org/kote/vice_city/thumb.9977f747.jpg",⤶ "packageType": 1,⤶ "updated": 1626557106,⤶ "usersNow": 0,⤶ "usersDay": 5,⤶ "usersMonth": 17,⤶ "usersTotal": 17,⤶ "tags": []⤶ }⤶ ]⤶ }⤶ ```⤶ ⤶ ## GET /sbox/asset/list⤶ ⤶ ### Params⤶ ⤶ `type`: `map` or `gamemode`.⤶ `order`: `trending`, `popular`, `newest`, `live`. Defaults to `trending`. `search`: Any search query. `category` (An Index Value starting at 1): | Index | Sort-By | |:-------:|:---------------------:| |1 | SandBox | |2 | Tech Demo/Expermental | |3 | Sports | |4 | Shooting | |5 | Parkour | |6 | Social | |7 | Meme | |8 | Roleplay | |9 | Racing | |10 | Mystery | |11 | Survival | |12 | Animals | |13 | Food | |14 | Strategy | |15 | Space | |16 | Fighting | |17 | Retro | |18 | Music | |19 | Art | |20 | Tycoon | ### Returns A list of `Package`s. ### Example Request [/sbox/asset/list?type=map&order=trending&search=Construct](http://apix.facepunch.com/api/sbox/asset/list?type=map&order=trending&search=Construct) ### Example Response ``` [ { "org": { "ident": "facepunch", "title": "Facepunch" }, "ident": "construct", "title": "Construct", "summary": "A simple construct map", "thumb": "https://files.facepunch.com/sbox/org/facepunch/construct/thumb.2f5f6e0a.jpg", "packageType": 1, "updated": 1620642104, "usersNow": 1, "usersDay": 42, "usersMonth": 357, "usersTotal": 480, "tags": [] }, { "org": { "ident": "phar", "title": "phar0" }, "ident": "construct_racing", "title": "Construct Race Edition BETA", "summary": "Construct but in Race track form. Fast compile for now.", "thumb": "https://files.facepunch.com/sbox/org/phar/construct_racing/thumb.32093d46.jpg", "packageType": 1, "updated": 1626114531, "usersNow": 0, "usersDay": 1, "usersMonth": 19, "usersTotal": 19, "tags": [] } ] ``` # Other ## Finding an Org There's no known endpoint for organizations. This is the closest you can get: 1. Visit several endpoints (`/asset/find?type={map}|{gamemode}`, `/menu/index`) and collect a list of orgs with their gamemode idents 2. Search that list for an org that matches the ident we're looking for 3. Visit `/asset/get?id={org}.{ident}` 4. Get the title & description for the org from this ## Player Counts Player accounts appear to use the Steam Lobby API; this means that an active Steam instance is required, using an account with access to s&box. To enumerate through lobbies, use [Steamworks.SteamMatchmaking.LobbyList](https://wiki.facepunch.com/steamworks/SteamMatchmaking.LobbyList). ⤶ ## Getting S&box Commit Logs⤶ ⤶ <validate>The only way to get more than 50 results is iterating through pages with a for loop</validate>⤶ ⤶ Commits can be retrieved from the endpoint [`https://commits.facepunch.com/r/sbox?format=json`](https://commits.facepunch.com/r/sbox?format=json).⤶ By default, this will return 50 of the most recent commit logs since the beginning of S&Box. You can further narrow the search using one or a combination of the following parameters:⤶ ⤶ `branch`: Name of Branch (e.g. `listener`)⤶ ⤶ `user`: Name of User listed on commit (e.g. `Layla`)⤶ ⤶ `p` (pages): Skips 50 commits at a time from the latest commit. Index starts at 1. (e.g. `p=3` will skip the first 100 commits)⤶ ⤶ ⤶ If you want to search for an individual commit by ID (which can be found within the endpoint above), you can use the endpoint `https://commits.facepunch.com/` followed by the ID number of the commit log and a format type of JSON or RSS.⤶ ⤶ ### Example Request⤶ ⤶ `https://commits.facepunch.com/388723?format=json`⤶ This endpoint will get a single commit with the ID of `388723`.⤶ ⤶ ### Example Response⤶ ⤶ ```⤶ {⤶ "total":1,⤶ "skip":0,⤶ "take":50,⤶ "results":[⤶ {⤶ "id":388723,⤶ "repo":"sbox",⤶ "branch":"master",⤶ "changeset":"59343d",⤶ "created":"2021-08-09T19:50:03",⤶ "message":"Revert \u0022Rework VR spectator view to work on console view, still need to fix offset\u0022\n\nThis reverts commit 2f1fa0584ab9e4c52d2f9cc5cdbd7f37e86c9b36.",⤶ "user":{⤶ "name":"Sam",⤶ "avatar":"https://files.facepunch.com/web/avatar/486779-22063427.png"⤶ }⤶ }⤶ ]⤶ }⤶ ```