# ZOOM Platform Library Integration Docs
We are undergoing a complete rework of our entire infrastructure when it comes to downloading, installing, and updating our titles.  
Part of this rework will include an open and fully documented spec including auth, downloading, parsing and installation for every platform so that anyone can implement our library with their launcher of choice.  

Until that is complete and ready for the public, here is some documentation on how library integration can work with our current installers. These docs will be periodically updated and the API will be updated within the restrictions of the current installer workflow. There will be no official integrations using this API.

This documentation will not cover the JSON responses or how to handle them. They are mostly self-explanatory. See existing implementations if you need a reference.  
If you have any questions or need more information, email `jmartinez@[the domain you're on]` or message [`zennn`](https://discord.com/users/100130956848943104) on Discord.

This documentation is available as markdown at [/li/docs.md](/li/docs.md).

## REST API

### Authentication

Use the regular [/login](/login) page to login and save the API key after login. This key will only work with the endpoints below.  

You may add the `?li=` query parameter with your app name as the value for a minimal login page.  Example: `/login?li=lutris`  
Once logged in, the user will be redirected to `/account`. You can make the redirect have the token value in the URL with the `return_li_token=true` param.  Example: `/login?li=lutris&return_li_token=true`

The token will be in the URL as `?li_token=li_XXXX`

---

### Making Requests
Every request should have these headers set:

- `Authorization`: with the value `Bearer TOKEN_HERE`.
- `Accept`: with the value `application/json`.

All responses will return [`401 Unauthorized`](https://developer.mozilla.org/docs/Web/HTTP/Reference/Status/401) if the auth token is invalid.
The token will invalidate after a password reset, so you will need to [log in](#authentication) again to get a new token.

---

### Rate Limits
All endpoints are rate limited. If limits are reached, they will respond with:
- [`429 Too Many Requests`](https://developer.mozilla.org/docs/Web/HTTP/Reference/Status/429) status.
- [Retry-After](https://developer.mozilla.org/docs/Web/HTTP/Headers/Retry-After) header

Be sure to handle this in your implementation.

---

### Check if User is Authenticated
If `GET` is used, the response body will contain an identifier for the user, you may use `HEAD` if your implementation doesn't need a response.

Methods
:   `GET`, `HEAD`

Path
:   `/li/loggedin`

**Response**:  
- `200 OK`: Token is valid and user is authenticated. A JSON object is returned if `GET` method is used.  
- `401 Unauthorized`: Token is invalid; prompt user to [log in](#authentication).

---

### Get Games Owned by User

Retrieves a list of games owned by the user, along with metadata for each.

Method
:   `GET`

Path
:   `/li/games`

Query Params
:   `page`: Should start at `0` and increment based on `total_pages` in the response.

**Response**:  
- `200 OK`: Returns an object. Add games to library via the `games` array. Use these keys for pagination: `total_pages`, `current_page`.

---

### Get metadata for a single Game

Method
:   `GET`

Path
:   `/li/game/{gameId}`

Path Parameter
:   `gameId`: Game UUID

**Response**:  
- `200 OK`: Game data object.
- [`403 Forbidden`](https://developer.mozilla.org/docs/Web/HTTP/Reference/Status/403): User does not own the game.
- [`404 Not Found`](https://developer.mozilla.org/docs/Web/HTTP/Reference/Status/404): Game does not exist.

---

### Get Files for a Game

Method
:   `GET`

Path
:   `/li/game/{gameId}/files`

Path Parameter
:   `gameId`: Game UUID

**Response**:  
- `200 OK`: Array of File Objects.
- [`403 Forbidden`](https://developer.mozilla.org/docs/Web/HTTP/Reference/Status/403): User does not own the game.
- [`404 Not Found`](https://developer.mozilla.org/docs/Web/HTTP/Reference/Status/404): Game does not exist.

---

### Get metadata for a single File

Method
:   `GET`

Path
:   `/li/file/{fileId}`

Path Parameter
:   `fileId`: File UUID

**Response**:  
- `200 OK`: File data object.
- [`403 Forbidden`](https://developer.mozilla.org/docs/Web/HTTP/Reference/Status/403): User does not own the Game that this File is for.
- [`404 Not Found`](https://developer.mozilla.org/docs/Web/HTTP/Reference/Status/404): File does not exist.

---

### Get File download info
Only call this endpoint when you're ready to start the download.

Method
:   `GET`

Path
:   `/li/download/{fileId}`

Path Parameter
:   `fileId`: File UUID

**Response**:  
- `200 OK`: Link and link expire time.
- [`403 Forbidden`](https://developer.mozilla.org/docs/Web/HTTP/Reference/Status/403): User does not own the Game that this File is for.
- [`404 Not Found`](https://developer.mozilla.org/docs/Web/HTTP/Reference/Status/404): File does not exist.

---

## Installer Info

### Notes on extracting installer files
You should let users install games by going through the installation process.
Many games have post install tasks that are required for the game to work. And many add required registry entries based on the system.  
If you decide to "install" games by extracting the installer, these post install tasks won't run and some games will not work at all.  
Installing DLC also requires a proper base game install.  

Another reason to not extract installers is that some installers will have options only available via the UI.  
Example: [Duke Nukem Manhattan Project](https://www.zoom-platform.com/product/duke-nukem-manhattan-project) allows the user to choose between the Original or Enhanced edition.

You can reduce some of the installer windows by [using an .inf file and pre-adding some registry entries that the installer would add.](https://github.com/ZOOM-Platform/zoom-platform.sh/blob/main/src.sh#L652-L699)

### Getting game info
- Registry (if a game is already installed): `HKLM\SOFTWARE\ZOOM PLATFORM\Arthur's Computer Adventure`
- Extract ID from installer exe: [https://github.com/doZennn/innoextract](https://github.com/doZennn/innoextract) with `--zoom-game-id`

    