BukkitWiki

Welcome to the BukkitWiki!

This Wiki is home to Bukkit's documentation and regulations surrounding the Bukkit Project and it's services. Want to help out? We would love to have you! Signup to get started!

READ MORE

BukkitWiki
m (Clarify recommended User-Agent header contents)
m (Undo revision 13947 by 172.31.25.79 (talk))
 
(8 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
== Introduction ==
 
== Introduction ==
   
The Curse server mods API allows developers to receive information on the latest available files for their project in JSON form. The API has two available endpoints, which should be requested with the GET HTTP method. An API key can be optionally specified (keys can be obtained from [https://dev.bukkit.org/home/servermods-apikey/ this page]) with the use of the '''X-API-Key''' header - otherwise the API can be used anonymously. The base URL for all requests is https://api.curseforge.com/servermods/. Developers should make use of the '''User-Agent''' header and use it to identify their application in the form of "User-Agent: {Application Name}/v{version} (by {author})". Care should be taken to ensure that API Keys are not inadvertently hard-coded or embedded into applications or plugins.
+
The Curse server mods API allows developers to receive information on the latest available files for their project in JSON form. The API has two available endpoints, which should be requested with the GET HTTP method. An API key can be optionally specified with the use of the '''X-API-Key''' header - otherwise the API can be used anonymously. The base URL for all requests is https://api.curseforge.com/servermods/. Developers should make use of the '''User-Agent''' header and use it to identify their application in the form of "User-Agent: {Application Name}/v{version} (by {author})". Care should be taken to ensure that API Keys are not inadvertently hard-coded or embedded into applications or plugins.
  +
  +
We encourage server admins to use their own API key which can be generated at https://dev.bukkit.org/home/servermods-apikey/. Please note that the server mods API key is '''completely separate''' to the BukkitDev API key (https://dev.bukkit.org/home/api-key/) which should never be used in an updater.
   
 
== Searching for project IDs ==
 
== Searching for project IDs ==
Line 47: Line 49:
 
"downloadUrl":"http:\/\/servermods.cursecdn.com\/files\/553\/160\/yoda.mp3",
 
"downloadUrl":"http:\/\/servermods.cursecdn.com\/files\/553\/160\/yoda.mp3",
 
"fileName":"yoda.mp3",
 
"fileName":"yoda.mp3",
  +
"fileUrl":"http:\/\/www.curseforge.com\/files\/553160",
 
"gameVersion":"1.4.7",
 
"gameVersion":"1.4.7",
  +
"md5":"bc301c973d5572e8126930e5e3cc9d10",
 
"name":"v0.1",
 
"name":"v0.1",
 
"projectId":33921,
 
"projectId":33921,
Line 53: Line 57:
 
}
 
}
 
]</source></blockquote>
 
]</source></blockquote>
  +
  +
The "fileUrl" field gives a link to the file changelog page. In this case it will redirect to [http://dev.bukkit.org/bukkit-plugins/bukkitdevtest/files/1-v0-1/ http://dev.bukkit.org/bukkit-plugins/bukkitdevtest/files/1-v0-1/]. The "md5" field is the [http://en.wikipedia.org/wiki/MD5 MD5] checksum of the file and can be used to ensure that a file has downloaded correctly.
   
 
== Code examples ==
 
== Code examples ==
   
A simple example of API usage is BukkitDev lead Gravity's [https://github.com/h31ix/ServerModsAPI-Example ServerModsAPI-Example] project. This code is a simple example of how you can utilize the json-simple library included in Bukkit to query the API and determine the status of a project by its projectId.
+
A simple example of API usage is BukkitDev lead Gravity's [https://github.com/gravitylow/ServerModsAPI-Example ServerModsAPI-Example] project. This code is a simple example of how you can utilize the json-simple library included in Bukkit to query the API and determine the status of a project by its projectId.
   
A more complex example is provided by Gravity's [https://github.com/h31ix/Updater Updater], a full-featured class you may use in your plugin. An example usage is below, utilizing Updater to check for updates and choosing not to download them.
+
A more complex example is provided by Gravity's [https://github.com/gravitylow/Updater Updater], a full-featured class you may use in your plugin. An example usage is below, utilizing Updater to check for updates and choosing not to download them.
   
 
<blockquote><source lang="java">Updater updater = new Updater(this, 55555, this.getFile(), UpdateType.NO_DOWNLOAD, true);
 
<blockquote><source lang="java">Updater updater = new Updater(this, 55555, this.getFile(), UpdateType.NO_DOWNLOAD, true);
 
if (updater.getResult() == UpdateResult.UPDATE_AVAILABLE) {
 
if (updater.getResult() == UpdateResult.UPDATE_AVAILABLE) {
this.getLogger().info("New version available! " + updater.getLatestVersionString());
+
this.getLogger().info("New version available! " + updater.getLatestName());
 
}</source></blockquote>
 
}</source></blockquote>
  +
  +
Care should be taken to ensure that you comply with the [[BukkitDev:Project_Submission_Guidelines#Automatic_Update_checking_.26_downloading|guidelines]] when making use of an automatic update checker or downloader.

Latest revision as of 07:01, 29 October 2017

Introduction

The Curse server mods API allows developers to receive information on the latest available files for their project in JSON form. The API has two available endpoints, which should be requested with the GET HTTP method. An API key can be optionally specified with the use of the X-API-Key header - otherwise the API can be used anonymously. The base URL for all requests is https://api.curseforge.com/servermods/. Developers should make use of the User-Agent header and use it to identify their application in the form of "User-Agent: {Application Name}/v{version} (by {author})". Care should be taken to ensure that API Keys are not inadvertently hard-coded or embedded into applications or plugins.

We encourage server admins to use their own API key which can be generated at https://dev.bukkit.org/home/servermods-apikey/. Please note that the server mods API key is completely separate to the BukkitDev API key (https://dev.bukkit.org/home/api-key/) which should never be used in an updater.

Searching for project IDs

The projects endpoint allows developers to convert a slug (e.g. worldedit) found in the BukkitDev plugin URL to its numeric identifier. The endpoint accepts searches for matching projects from the supplied search term. The search term should be passed in via the search GET argument.

An example request:

URL: https://api.curseforge.com/servermods/projects?search=worldedit

Output:

[
   {
      "id":54713,
      "name":"LimitedWorldEdit",
      "slug":"limitedworldedit",
      "stage":"beta"
   },
   {
      "id":55226,
      "name":"AsyncWorldEdit",
      "slug":"async_worldedit",
      "stage":"beta"
   },
   {
      "id":31043,
      "name":"WorldEdit",
      "slug":"worldedit",
      "stage":"release"
   }
]

Retrieving a file listing for projects

The files endpoint allows developers to obtain a list of the latest normal files attached to a project. The endpoint allows for multiple projects to be looked up at once. The project identifiers should be passed via the projectIds argument, which accepts comma-separated input as well as a single ID.

An example request:

URL: https://api.curseforge.com/servermods/files?projectIds=33921

Output:

[
   {
      "downloadUrl":"http:\/\/servermods.cursecdn.com\/files\/553\/160\/yoda.mp3",
      "fileName":"yoda.mp3",
      "fileUrl":"http:\/\/www.curseforge.com\/files\/553160",
      "gameVersion":"1.4.7",
      "md5":"bc301c973d5572e8126930e5e3cc9d10",
      "name":"v0.1",
      "projectId":33921,
      "releaseType":"beta"
   }
]

The "fileUrl" field gives a link to the file changelog page. In this case it will redirect to http://dev.bukkit.org/bukkit-plugins/bukkitdevtest/files/1-v0-1/. The "md5" field is the MD5 checksum of the file and can be used to ensure that a file has downloaded correctly.

Code examples

A simple example of API usage is BukkitDev lead Gravity's ServerModsAPI-Example project. This code is a simple example of how you can utilize the json-simple library included in Bukkit to query the API and determine the status of a project by its projectId.

A more complex example is provided by Gravity's Updater, a full-featured class you may use in your plugin. An example usage is below, utilizing Updater to check for updates and choosing not to download them.

Updater updater = new Updater(this, 55555, this.getFile(), UpdateType.NO_DOWNLOAD, true);
if (updater.getResult() == UpdateResult.UPDATE_AVAILABLE) {
    this.getLogger().info("New version available! " + updater.getLatestName());
}

Care should be taken to ensure that you comply with the guidelines when making use of an automatic update checker or downloader.