contentdb/app/flatpages/help/api.md

321 lines
11 KiB
Markdown
Raw Normal View History

2019-11-22 15:33:22 +01:00
title: API
2021-02-02 23:47:46 +01:00
## Responses and Error Handling
If there is an error, the response will be JSON similar to the following with a non-200 status code:
```json
{
"success": false,
"error": "The error message"
}
```
Successful GET requests will return the resource's information directly as a JSON response.
Other successful results will return a dictionary with `success` equaling true, and
often other keys with information. For example:
```js
{
"success": true,
"release": {
/* same as returned by a GET */
}
}
```
2021-02-02 23:47:46 +01:00
2019-11-22 15:33:22 +01:00
## Authentication
2021-02-02 23:47:46 +01:00
Not all endpoints require authentication, but it is done using Bearer tokens:
2019-11-22 15:33:22 +01:00
```bash
2021-02-02 23:47:46 +01:00
curl https://content.minetest.net/api/whoami/ \
-H "Authorization: Bearer YOURTOKEN"
```
2019-11-22 15:33:22 +01:00
Tokens can be attained by visiting [Settings > API Tokens](/user/tokens/).
2021-02-02 23:41:48 +01:00
* GET `/api/whoami/`: JSON dictionary with the following keys:
* `is_authenticated`: True on successful API authentication
* `username`: Username of the user authenticated as, null otherwise.
2021-02-02 18:09:25 +01:00
* 4xx status codes will be thrown on unsupported authentication type, invalid access token, or other errors.
2019-11-22 15:33:22 +01:00
2021-02-02 23:41:48 +01:00
2021-02-02 21:05:24 +01:00
## Packages
2019-11-22 15:33:22 +01:00
2021-02-02 22:35:29 +01:00
* GET `/api/packages/` (List)
* See [Package Queries](#package-queries)
* GET `/api/packages/<username>/<name>/` (Read)
* PUT `/api/packages/<author>/<name>/` (Update)
2021-02-03 13:50:16 +01:00
* Requires authentication.
2021-02-02 23:47:46 +01:00
* JSON dictionary with any of these keys (all are optional, null to delete Nullables):
* `type`: One of `GAME`, `MOD`, `TXP`.
2021-02-02 22:35:29 +01:00
* `title`: Human-readable title.
2021-02-02 23:47:46 +01:00
* `name`: Technical name (needs permission if already approved).
2021-02-02 23:34:51 +01:00
* `short_description`
2021-02-05 16:29:44 +01:00
* `tags`: List of [tag](#tags) names.
* `content_warnings`: List of [content warning](#content-warnings) names.
* `license`: A [license](#licenses) name.
* `media_license`: A [license](#licenses) name.
* `long_description`: Long markdown description.
2021-02-02 22:35:29 +01:00
* `repo`: Git repo URL.
* `website`: Website URL.
* `issue_tracker`: Issue tracker URL.
2021-02-02 23:47:46 +01:00
* `forums`: forum topic ID.
2020-06-05 05:48:53 +02:00
* GET `/api/packages/<username>/<name>/dependencies/`
2021-02-02 18:09:25 +01:00
* If query argument `only_hard` is present, only hard deps will be returned.
2019-11-22 15:33:22 +01:00
2021-02-02 23:47:46 +01:00
Examples:
```bash
2021-03-05 13:55:21 +01:00
# Edit package
2021-02-02 23:47:46 +01:00
curl -X PUT http://localhost:5123/api/packages/username/name/ \
-H "Authorization: Bearer YOURTOKEN" -H "Content-Type: application/json" \
-d '{ "title": "Foo bar", "tags": ["pvp", "survival"], "license": "MIT" }'
2021-02-02 23:47:46 +01:00
# Remove website URL
curl -X PUT http://localhost:5123/api/packages/username/name/ \
-H "Authorization: Bearer YOURTOKEN" -H "Content-Type: application/json" \
-d '{ "website": null }'
```
2021-02-02 21:05:24 +01:00
### Package Queries
Example:
/api/packages/?type=mod&type=game&q=mobs+fun&hide=nonfree&hide=gore
Supported query parameters:
2021-02-02 23:41:48 +01:00
* `type`: Package types (`mod`, `game`, `txp`).
* `q`: Query string.
* `author`: Filter by author.
* `tag`: Filter by tags.
* `random`: When present, enable random ordering and ignore `sort`.
* `limit`: Return at most `limit` packages.
* `hide`: Hide content based on [Content Flags](/help/content_flags/).
* `sort`: Sort by (`name`, `title`, `score`, `reviews`, `downloads`, `created_at`, `approved_at`, `last_release`).
* `order`: Sort ascending (`asc`) or descending (`desc`).
* `protocol_version`: Only show packages supported by this Minetest protocol version.
* `engine_version`: Only show packages supported by this Minetest engine version, eg: `5.3.0`.
* `fmt`: How the response is formated.
* `keys`: author/name only.
* `short`: stuff needed for the Minetest client.
2021-02-02 21:05:24 +01:00
## Releases
2020-01-24 21:21:40 +01:00
2021-03-05 13:55:21 +01:00
* GET `/api/releases/` (List)
* Limited to 30 most recent releases.
* Optional arguments:
* `author`: Filter by author
* `maintainer`: Filter by maintainer
2021-02-02 18:09:28 +01:00
* Returns array of release dictionaries with keys:
* `id`: release ID
* `title`: human-readable title
* `release_date`: Date released
* `url`: download URL
* `commit`: commit hash or null
* `downloads`: number of downloads
* `min_minetest_version`: dict or null, minimum supported minetest version (inclusive).
* `max_minetest_version`: dict or null, minimum supported minetest version (inclusive).
2021-03-05 13:55:21 +01:00
* `package`
2021-04-10 17:30:19 +02:00
* `author`: author username
* `name`: technical name
2021-03-05 13:55:21 +01:00
* `type`: `mod`, `game`, or `txp`
* GET `/api/packages/<username>/<name>/releases/` (List)
* Returns array of release dictionaries, see above, but without package info.
2021-02-02 18:09:28 +01:00
* GET `/api/packages/<username>/<name>/releases/<id>/` (Read)
* POST `/api/packages/<username>/<name>/releases/new/` (Create)
2021-02-02 18:09:25 +01:00
* Requires authentication.
2021-02-02 18:09:28 +01:00
* Body can be JSON or multipart form data. Zip uploads must be multipart form data.
2021-02-02 18:09:25 +01:00
* `title`: human-readable name of the release.
* For Git release creation:
* `method`: must be `git`.
* `ref`: (Optional) git reference, eg: `master`.
* For zip upload release creation:
* `file`: multipart file to upload, like `<input type="file" name="file">`.
* `commit`: (Optional) Source Git commit hash, for informational purposes.
2021-02-02 18:09:25 +01:00
* You can set min and max Minetest Versions [using the content's .conf file](/help/package_config/).
2021-02-02 18:09:28 +01:00
* DELETE `/api/packages/<username>/<name>/releases/<id>/` (Delete)
* Requires authentication.
* Deletes release.
Examples:
```bash
# Create release from Git
curl -X POST https://content.minetest.net/api/packages/username/name/releases/new/ \
2021-02-02 18:09:25 +01:00
-H "Authorization: Bearer YOURTOKEN" -H "Content-Type: application/json" \
2021-02-02 23:47:46 +01:00
-d '{ "method": "git", "title": "My Release", "ref": "master" }'
# Create release from zip upload
2021-02-02 18:09:28 +01:00
curl -X POST https://content.minetest.net/api/packages/username/name/releases/new/ \
2021-02-02 18:09:25 +01:00
-H "Authorization: Bearer YOURTOKEN" \
-F title="My Release" -F file=@path/to/file.zip
2021-02-02 18:09:28 +01:00
# Create release from zip upload with commit hash
curl -X POST https://content.minetest.net/api/packages/username/name/releases/new/ \
-H "Authorization: Bearer YOURTOKEN" \
-F title="My Release" -F commit="8ef74deec170a8ce789f6055a59d43876d16a7ea" -F file=@path/to/file.zip
2021-02-02 18:09:28 +01:00
# Delete release
curl -X DELETE https://content.minetest.net/api/packages/username/name/releases/3/ \
-H "Authorization: Bearer YOURTOKEN"
```
2020-01-24 21:21:40 +01:00
2021-02-02 21:05:24 +01:00
## Screenshots
2021-02-02 18:09:23 +01:00
2021-02-02 18:09:25 +01:00
* GET `/api/packages/<username>/<name>/screenshots/` (List)
* Returns array of screenshot dictionaries with keys:
* `id`: screenshot ID
* `approved`: true if approved and visible.
* `title`: human-readable name for the screenshot, shown as a caption and alt text.
* `url`: absolute URL to screenshot.
2021-02-02 18:29:03 +01:00
* `created_at`: ISO time.
2021-02-02 18:09:25 +01:00
* `order`: Number used in ordering.
* GET `/api/packages/<username>/<name>/screenshots/<id>/` (Read)
* Returns screenshot dictionary like above.
2021-02-02 18:09:23 +01:00
* POST `/api/packages/<username>/<name>/screenshots/new/` (Create)
2021-02-02 18:09:25 +01:00
* Requires authentication.
* Body is multipart form data.
* `title`: human-readable name for the screenshot, shown as a caption and alt text.
* `file`: multipart file to upload, like `<input type=file>`.
* DELETE `/api/packages/<username>/<name>/screenshots/<id>/` (Delete)
* Requires authentication.
* Deletes screenshot.
* POST `/api/packages/<username>/<name>/screenshots/order/`
* Requires authentication.
* Body is a JSON array containing the screenshot IDs in their order.
2021-02-02 18:09:23 +01:00
2021-02-02 18:09:25 +01:00
Examples:
2021-02-02 18:09:23 +01:00
```bash
# Create screenshot
2021-02-02 18:09:28 +01:00
curl -X POST https://content.minetest.net/api/packages/username/name/screenshots/new/ \
2021-02-02 18:09:25 +01:00
-H "Authorization: Bearer YOURTOKEN" \
-F title="My Release" -F file=@path/to/screnshot.png
# Delete screenshot
curl -X DELETE https://content.minetest.net/api/packages/username/name/screenshots/3/ \
-H "Authorization: Bearer YOURTOKEN"
# Reorder screenshots
curl -X POST https://content.minetest.net/api/packages/username/name/screenshots/order/ \
-H "Authorization: Bearer YOURTOKEN" -H "Content-Type: application/json" \
-d "[13, 2, 5, 7]"
2021-02-02 18:09:23 +01:00
```
2021-02-02 21:05:24 +01:00
2021-11-24 17:33:37 +01:00
## Reviews
* GET `/api/packages/<username></<name>/releases/` (List)
* Returns array of review dictionaries with keys:
* `user`: dictionary with `display_name` and `username`.
* `title`: review title
* `comment`: the text
* `is_positive`: boolean
* `created_at`: iso timestamp
* `votes`: dictionary with `helpful` and `unhelpful`,
* GET `/api/reviews/` (List)
* Above, but for all packages.
* Each review has a `package` dictionary with `type`, `author` and `name`
Example:
```json
[
{
"comment": "This is a really good mod!",
"created_at": "2021-11-24T16:18:33.764084",
"is_positive": true,
"title": "Really good",
"user": {
"display_name": "rubenwardy",
"username": "rubenwardy"
},
"votes": {
"helpful": 0,
"unhelpful": 0
}
}
]
```
2021-02-02 21:05:24 +01:00
## Topics
2019-11-22 15:33:22 +01:00
2021-02-05 16:29:44 +01:00
* GET `/api/topics/` ([View](/api/topics/)): Supports [Package Queries](#package-queries), and the following two options:
2021-02-02 23:41:48 +01:00
* `show_added`: Show topics which exist as packages, default true.
* `show_discarded`: Show topics which have been marked as outdated, default false.
2019-11-22 15:33:22 +01:00
2021-02-02 21:05:24 +01:00
### Topic Queries
Example:
2021-02-02 18:09:25 +01:00
/api/topics/?q=mobs
Supported query parameters:
2021-02-02 23:41:48 +01:00
* `q`: Query string.
* `sort`: Sort by (`name`, `views`, `date`).
* `order`: Sort ascending (`asc`) or descending (`desc`).
* `show_added`: Show topics that have an existing package.
* `show_discarded`: Show topics marked as discarded.
* `limit`: Return at most `limit` topics.
2021-02-02 21:05:24 +01:00
2021-02-05 16:29:44 +01:00
## Types
2021-02-02 21:05:24 +01:00
2021-02-05 16:29:44 +01:00
### Tags
2021-02-02 21:05:24 +01:00
2021-02-05 16:29:44 +01:00
* GET `/api/tags/` ([View](/api/tags/)): List of:
* `name`: technical name
* `title`: human-readable title
* `description`: tag description or null
### Content Warnings
* GET `/api/content_warnings/` ([View](/api/content_warnings/)): List of:
2021-02-02 23:41:48 +01:00
* `name`: technical name
* `title`: human-readable title
* `description`: tag description or null
2021-02-05 16:29:44 +01:00
### Licenses
* GET `/api/licenses/` ([View](/api/licenses/)): List of:
2021-02-02 23:41:48 +01:00
* `name`
* `is_foss`: whether the license is foss
2021-02-05 16:29:44 +01:00
### Minetest Versions
* GET `/api/minetest_versions/` ([View](/api/minetest_versions/))
* `name`: Version name.
* `is_dev`: boolean, is dev version.
* `protocol_version`: protocol version umber.
## Misc
* GET `/api/scores/` ([View](/api/scores/))
* See [Top Packages Algorithm](/help/top_packages/).
* Supports [Package Queries](#package-queries).
* Returns list of:
* `author`: package author name.
* `name`: package technical name.
* `downloads`: number of downloads.
* `score`: total package score.
* `score_reviews`: score from reviews.
* `score_downloads`: score from downloads.
* GET `/api/homepage/` ([View](/api/homepage/)) - get contents of homepage.
2021-02-02 23:41:48 +01:00
* `count`: number of packages
* `downloads`: get number of downloads
* `new`: new packages
* `updated`: recently updated packages
* `pop_mod`: popular mods
* `pop_txp`: popular textures
* `pop_game`: popular games
* `high_reviewed`: highest reviewed