Skip to content

Commit 41aa580

Browse files
authored
Document a couple of API example scripts (#284)
1 parent 5ba34d0 commit 41aa580

File tree

2 files changed

+68
-9
lines changed

2 files changed

+68
-9
lines changed

docs/misc/downloads-api.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/misc/downloads-api.mdx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
slug: /downloads-api
3+
description: Paper provides a downloads API that you can use to access builds.
4+
---
5+
6+
# Downloads API
7+
8+
PaperMC provides a downloads API to facilitate automated downloads access. Full documentation can be
9+
found on the [Downloads API Docs](https://api.papermc.io/docs).
10+
11+
:::danger
12+
13+
We emphatically **do not recommend** using unstable builds or auto-updaters within production environments.
14+
15+
:::
16+
17+
:::info
18+
19+
We require `jq` to be installed for the examples below. You can install it with `sudo apt-get install jq` on Debian/Ubuntu
20+
21+
:::
22+
23+
## Getting Latest Stable Build Number
24+
25+
<VersionFormattedCode language={"shell"}>
26+
```
27+
#!/bin/bash
28+
29+
PROJECT="paper"
30+
MINECRAFT_VERSION="%%_MAJ_MIN_MC_%%"
31+
32+
LATEST_BUILD=$(curl -s https://api.papermc.io/v2/projects/${PROJECT}/versions/${MINECRAFT_VERSION}/builds | \
33+
jq '.builds | map(select(.channel == "default") | .build) | .[-1]')
34+
35+
echo "Latest build is $LATEST_BUILD"
36+
```
37+
</VersionFormattedCode>
38+
39+
This will get the latest stable build for the given project and Minecraft version.
40+
41+
## Downloading Latest Stable Build
42+
43+
<VersionFormattedCode language={"shell"}>
44+
```
45+
#!/bin/bash
46+
47+
PROJECT="paper"
48+
MINECRAFT_VERSION="%%_MAJ_MIN_MC_%%"
49+
50+
LATEST_VERSION=$(curl -s https://api.papermc.io/v2/projects/paper | \
51+
jq -r '.versions[-1]'
52+
53+
LATEST_BUILD=$(curl -s https://api.papermc.io/v2/projects/${PROJECT}/versions/${MINECRAFT_VERSION}/builds | \
54+
jq -r '.builds | map(select(.channel == "default") | .build) | .[-1]')
55+
56+
JAR_NAME=paper-${LATEST_VERSION}-${LATEST_BUILD}.jar
57+
58+
PAPERMC_URL="https://api.papermc.io/v2/projects/paper/versions/${LATEST_VERSION}/builds/${LATEST_BUILD}/downloads/${JAR_NAME}"
59+
60+
# Download the latest PaperMC version
61+
curl -o server.jar $PAPERMC_URL
62+
echo "Downloads completed"
63+
```
64+
</VersionFormattedCode>
65+
66+
This is the most common use case for the API. It will download the latest stable build for the given project and
67+
Minecraft version. You should always serve & use the stable builds. Experimental builds are prone to error and
68+
do not receive support.

0 commit comments

Comments
 (0)