Difference between revisions of "External Services and Tools/API Documentation"

From BattleMaster Wiki
Jump to navigation Jump to search
m (→‎realm.php: added capitol to realm data (active at next server update))
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{RightTOC}}
 
{{RightTOC}}
All scripts are located at ''<nowiki>http://battlemaster.org/data/</nowiki>''. So, for example, to get the region data of [[Akesh Temple]], you would access the URL
+
== Introduction ==
 +
All scripts are located at ''<nowiki>http://battlemaster.org/data/</nowiki>''. So, for example, to get the region data of [[Akesh Temple]], you would access the URL http://battlemaster.org/data/region.php?World=1&ID=1.
  
http://battlemaster.org/data/region.php?World=1&ID=1.
+
=== Request Structure ===
 +
All API requests should be properly formatted HTTP GET requests, with special attention paid to the Authorization and Accept headers. All Requests on this page will include formatting details of the response along with indication on whether they require authentication or not. Requests that do not require authentication will not be affected if your application sends the Authorization header with a valid token--this header will be ignored unless needed.
  
== API Change Requests ==
+
=== Return Types ===
If you want changes to the API, especially new data disclosed, please post to the talk page. '''Include what you need it for'''. We follow the X-Window Manifesto: ''"Do not add new functionality unless you know of some real application that will require it."''
+
The API will always expect an Accept header declaration and will error out with an XML response if one is not provided. Acceptable Accept headers are "text/xml", "application/xml", and "application/json".
  
 +
All error codes will return in the data format requested (if one is requested), and all requests will include appropriate HTTP Status Codes (usually 200, 400, or 404).
  
== listrealms.php ==
+
Finally, all requests will return license and metadata information.
{| style="background:#eee;"
 
|-
 
! Parameter
 
! Type
 
! Meaning
 
|-valign="top"
 
| World
 
| integer
 
| Game world ID you access, see [[#World IDs]]
 
|}
 
  
Output:
+
== Unauthenticated Requests ==
<listing>
+
The following requests do not require use of the Authorization HTTP header. All requests require use of the Accept HTTP header to indicate return type.
  <realm-ids> ''comma-seperated list of integers'' </realm-ids>
 
  <realm-names> ''comma-seperated list of strings'' </realm-names>
 
</listing>
 
  
=== Example ===
+
* Manual Page - Access Point - Input(s) - Description
; Realms on the East Island : http://battlemaster.org/data/listrealms.php?World=1
+
* [[/listrealms|listrealms]] - /data/listrealms - /{world} - Lists all realms on an island.
 +
* [[/listregions|listregions]] - /data/listregions - /{world} - Lists all regions on an island.
 +
* [[/region|region]] - /data/region - /{world}/{region} - List details about a particular region.
 +
* [[/realm|realm]] - /data/realm - /{world}/{realm}/{withregions} - List details about a particular realm.
 +
* [[/character|character]] - /data/character - /{world}/{character} - List details about a particular character.
 +
* [[/family|family]] - /data/family - /{family} - List details on a particular family. Will not list characters of a family.
 +
* [[/active-nobles|active-nobles]] - /data/active-nobles - /{family} - Lists active nobles of a family, with family information as well.
 +
* [[/active-characters|active-characters]] - /data/active-characters- /{family} - Lists active characters of a family, with family information as well. ''Added in v2''
 +
* [[/active-commoners|active-commoners]] - /data/active-commoners - /{family} - Lists active commoners of a family, with family information as well. ''Added in v2''
 +
* [[/all-commoners|all-commoners]] - /data/all-commoners - /{family} - Lists all commoners of a family, with family information as well. ''Added in v2''
 +
* [[/all-characters|all-characters]] - /data/all-characters- /{family} - Lists all characters of a family, with family information as well. ''Added in v2''
 +
* [[/all-nobles|all-nobles]] - /data/all-nobles - /{family} - Lists all nobles of a family, with family information as well. ''Added in v2''
 +
* [[/globals|globals]] - /data/globals - ''N/A''  - Returns the current day/night status, and time until next turn.
  
== region.php ==
+
== Authenticated Requests ==
{| style="background:#eee;"
+
These requests will always require at minimum, your user ID and your Application Key. The application key '''must''' be sent as part of the Authorization HTTP header as a Bearer token.  
|-
 
! Parameter
 
! Type
 
! Meaning
 
|-valign="top"
 
| World
 
| integer
 
| Game world ID you access, see [[#World IDs]]
 
|-valign="top"
 
| ID
 
| integer
 
| ID number of the region in question. You can find this for example by examining the URL of the "Details" link on the Region List page, or (if the page is already set up correctly) on the region's page here in the wiki.  Can be replaced by Name
 
|-valign="top"
 
| Name
 
| text/string
 
| Can replace ID.  Name of the Region being queried.
 
|}
 
  
 +
If your Application key was 123456abcdef, for instance, your Authorization header would read: "Bearer 123456abcdef".
  
Output:
+
Any requests that do not supply valid credentials will return a HTTP Status Code 401, "Unauthorized".
<regiondata>
 
    <continent> ''string'' </continent>
 
    <id> ''integer'' </id>
 
    <name> ''string'' </name>
 
    <type> ''string'' </type>
 
    <area> ''string'' </area>
 
    <population> ''number'' </population>
 
    <economy> ''comma-seperated list of strings'' </economy>
 
    <realm> ''string'' </realm>
 
    <duchy> ''string'' </duchy>
 
    <lord> ''string'' </lord>
 
    <xpos> ''integer'' </xpos>
 
    <ypos> ''integer'' </ypos>
 
</regiondata>
 
 
 
=== Example ===
 
; The City of Libidizedd by ID : http://battlemaster.org/data/region.php?World=8&ID=200
 
; The City of Eidulb by name : http://battlemaster.org/data/region.php?World=8&Name=Eidulb
 
 
 
== realm.php ==
 
{| style="background:#eee;"
 
|-
 
! Parameter
 
! Type
 
! Meaning
 
|-valign="top"
 
| World
 
| integer
 
| Game world ID you access, see [[#World IDs]]
 
|-valign="top"
 
| ID
 
| integer
 
| ID number of the realm in question. You can find this for example by examining the URL of the "Details" link on the Realm List page, or (if the page is already set up correctly) on the realm's page here in the wiki.  Can be replaced by Name.
 
|-valign="top"
 
| Name
 
| text/string
 
| Can replace ID.  Name of the Realm being queried.
 
|-valign="top"
 
| WithRegions
 
| boolean
 
| ''optional'' - if given, a list of region IDs (for use in the region.php script) and region names is included. ''only use this if you need them, it is considerably more expensive on the database than without''
 
|}
 
 
 
Output:
 
<realmdata>
 
    <continent> ''string'' </continent>
 
    <id> ''integer'' </id>
 
    <name> ''string'' </name>
 
    <colour> ''HTML colour value'' </colour>
 
    <system> ''string'' </system>
 
    <rulertitle> ''string'' </rulertitle>
 
    <rulername> ''string'' </rulername>
 
    <generaltitle> ''string'' </generaltitle>
 
    <generalname> ''string'' </generalname>
 
    <judgetitle> ''string'' </judgetitle>
 
    <judgename> ''string'' </judgename>
 
    <bankertitle> ''string'' </bankertitle>
 
    <bankername> ''string'' </bankername>
 
    <capitol> ''integer'' </capitol>
 
</realmdata>
 
 
 
=== Example ===
 
; The Realm of Darka by ID : http://battlemaster.org/data/realm.php?World=2&ID=14
 
; The Realm of Arcaea by name, with regions : http://battlemaster.org/data/realm.php?World=7&Name=Arcaea&WithRegions=True
 
 
 
== character.php ==
 
{| style="background:#eee;"
 
|-
 
! Parameter
 
! Type
 
! Meaning
 
|-valign="top"
 
| World
 
| integer
 
| Game world ID you access, see [[#World IDs]]
 
|-valign="top"
 
| ID
 
| integer
 
| ID number of the character in question. This is usually only found in the source code of some pages. Name is more logical in this case.
 
|-valign="top"
 
| Name
 
| text/string
 
| Can replace ID. Name of the Noble being queried.
 
|}
 
 
 
Output:
 
<nobledata>
 
    <continent> ''string'' </continent>
 
    <id> ''integer'' </id>
 
    <name> ''string'' </name>
 
    <family> ''string'' </family>
 
    <mainclass> ''string'' </mainclass>
 
    <subclass> ''string'' </subclass>
 
    <age> ''integer'' </age>
 
    <honour> ''integer'' </honour>
 
    <prestige> ''integer'' </prestige>
 
    <rank> ''string'' </rank>
 
    <gender> ''string'' </gender>
 
    <region>''string''</region>
 
    <duchy> ''string'' </duchy>
 
    <realm> ''string'' </realm>
 
</nobledata>
 
 
 
=== Example ===
 
; The character Brance Indirik by ID : http://battlemaster.org/data/character.php?World=8&ID=34
 
; The character Taylin Indirik by name : http://battlemaster.org/data/character.php?World=7&Name=Taylin
 
 
 
== family.php ==
 
{| style="background:#eee;"
 
|-
 
! Parameter
 
! Type
 
! Meaning
 
|-valign="top"
 
| ID
 
| integer
 
| ID number of the family in question. This is identical to the User ID that can be found on the user details page.
 
|-valign="top"
 
| Name
 
| text/string
 
| Can replace ID. Name of the family being queried.
 
|}
 
 
 
Output:
 
<familydata>
 
    <id> ''integer'' </id>
 
    <name>  ''string'' </name>
 
    <fame>''integer'' </fame>
 
    <wealth> ''integer'' </wealth>
 
</familydata>
 
 
 
=== Example ===
 
; The Indirik family by ID : http://battlemaster.org/data/family.php?ID=14094
 
; The Anaris family by name : http://battlemaster.org/data/family.php?Name=Anaris
 
  
 +
* [[/player-data|player-data]] - /data/player-data - /{user ID} - Displays your player and character information, similar to your account page.  ''Coming in v2.1''
  
 
== Additional Information ==
 
== Additional Information ==
 
=== World IDs ===
 
=== World IDs ===
The various game worlds of BattleMaster are internally accessed through ID numbers. Here is the mapping:
+
The various game worlds of BattleMaster are internally accessed through ID numbers. If you interested in efficiency, IDs are checked for first. Here is the mapping:
 
{| style="background:#eee;"
 
{| style="background:#eee;"
 
|-
 
|-
Line 214: Line 67:
 
|}
 
|}
 
Yes, 3 and 5 are missing. They used to be the IDs of South-West and South-East Island.
 
Yes, 3 and 5 are missing. They used to be the IDs of South-West and South-East Island.
 
 
=== Other IDs ===
 
You can query most data sets by ID number or by name. Querying by name is considerably more expensive on our database, so we strongly encourage you to locally cache the ID/Name associations that you learn. That is why all datasets return the ID.
 
 
  
 
=== Output Values ===
 
=== Output Values ===
Line 225: Line 73:
 
  <bankername></bankername>
 
  <bankername></bankername>
 
Nevertheless, external tools should fail gracefully if an expected tag is missing.
 
Nevertheless, external tools should fail gracefully if an expected tag is missing.
 
  
 
=== XML Tree ===
 
=== XML Tree ===

Latest revision as of 10:06, 28 January 2022

Introduction

All scripts are located at http://battlemaster.org/data/. So, for example, to get the region data of Akesh Temple, you would access the URL http://battlemaster.org/data/region.php?World=1&ID=1.

Request Structure

All API requests should be properly formatted HTTP GET requests, with special attention paid to the Authorization and Accept headers. All Requests on this page will include formatting details of the response along with indication on whether they require authentication or not. Requests that do not require authentication will not be affected if your application sends the Authorization header with a valid token--this header will be ignored unless needed.

Return Types

The API will always expect an Accept header declaration and will error out with an XML response if one is not provided. Acceptable Accept headers are "text/xml", "application/xml", and "application/json".

All error codes will return in the data format requested (if one is requested), and all requests will include appropriate HTTP Status Codes (usually 200, 400, or 404).

Finally, all requests will return license and metadata information.

Unauthenticated Requests

The following requests do not require use of the Authorization HTTP header. All requests require use of the Accept HTTP header to indicate return type.

  • Manual Page - Access Point - Input(s) - Description
  • listrealms - /data/listrealms - /{world} - Lists all realms on an island.
  • listregions - /data/listregions - /{world} - Lists all regions on an island.
  • region - /data/region - /{world}/{region} - List details about a particular region.
  • realm - /data/realm - /{world}/{realm}/{withregions} - List details about a particular realm.
  • character - /data/character - /{world}/{character} - List details about a particular character.
  • family - /data/family - /{family} - List details on a particular family. Will not list characters of a family.
  • active-nobles - /data/active-nobles - /{family} - Lists active nobles of a family, with family information as well.
  • active-characters - /data/active-characters- /{family} - Lists active characters of a family, with family information as well. Added in v2
  • active-commoners - /data/active-commoners - /{family} - Lists active commoners of a family, with family information as well. Added in v2
  • all-commoners - /data/all-commoners - /{family} - Lists all commoners of a family, with family information as well. Added in v2
  • all-characters - /data/all-characters- /{family} - Lists all characters of a family, with family information as well. Added in v2
  • all-nobles - /data/all-nobles - /{family} - Lists all nobles of a family, with family information as well. Added in v2
  • globals - /data/globals - N/A - Returns the current day/night status, and time until next turn.

Authenticated Requests

These requests will always require at minimum, your user ID and your Application Key. The application key must be sent as part of the Authorization HTTP header as a Bearer token.

If your Application key was 123456abcdef, for instance, your Authorization header would read: "Bearer 123456abcdef".

Any requests that do not supply valid credentials will return a HTTP Status Code 401, "Unauthorized".

  • player-data - /data/player-data - /{user ID} - Displays your player and character information, similar to your account page. Coming in v2.1

Additional Information

World IDs

The various game worlds of BattleMaster are internally accessed through ID numbers. If you interested in efficiency, IDs are checked for first. Here is the mapping:

ID World
1 East Island
2 Atamara
4 Beluaterra
6 Colonies
7 Far East
8 Dwilight

Yes, 3 and 5 are missing. They used to be the IDs of South-West and South-East Island.

Output Values

Many values can be empty, e.g. when the realm currently has no banker, or if a region does not belong to a duchy (i.e. an imperial region). Empty values are always returned as empty strings, e.g.:

<bankername></bankername>

Nevertheless, external tools should fail gracefully if an expected tag is missing.

XML Tree

These data scripts were written with MediaWiki's External Data extension in mind. The extension does not parse an XML tree, but simply scans for key/value pairs. Therefore, we do not generate tree structures in our output. For example, in a pure XML environment, the output for realm governments would instead be something like

<ruler>
   <name> string </name>
   <title> string </title>
</ruler>

However, since the extension does not parse the tree, the next occurrance, say within the general tag would overwrite the variables "name" and "title".

Your application must, however, recognize and parse the XML tags. We can and will change the order of the tags as we see fit without notice, so do not use an approach like "ok, 2nd entry is the name..." - always do parse the tags.