Beruflich Dokumente
Kultur Dokumente
Official documentation
version 0.6
2010-05-15
Page 1/17
Table of contents
1 Introduction........................................................................................................................ 3 1.1 Welcome to the eAPI! ................................................................................................ 3 1.2 About the eAPI............................................................................................................ 3 1.2.1 History.................................................................................................................. 3 1.2.2 Uses.....................................................................................................................3 1.2.3 OAuth................................................................................................................... 4 1.3 Getting help.................................................................................................................4 2 Getting started....................................................................................................................4 2.1 Data formats............................................................................................................... 4 2.2 Errors.......................................................................................................................... 5 2.3 Feeds.......................................................................................................................... 5 2.3.1 General changes from eAPI v1........................................................................... 5 2.3.2 Citizen..................................................................................................................5 XML output................................................................................................................ 6 Changes.................................................................................................................... 6 2.3.3 Compressed Citizens ......................................................................................... 6 2.3.4 Country................................................................................................................ 7 XML output................................................................................................................ 7 Changes.................................................................................................................... 7 2.3.5 Region................................................................................................................. 7 XML output................................................................................................................ 8 Changes.................................................................................................................... 8 2.3.6 Regions by country..............................................................................................8 2.3.7 Wars by country...................................................................................................9 2.3.8 Citizens by Region............................................................................................... 9 2.3.9 Company............................................................................................................. 9 XML output.............................................................................................................. 10 Changes.................................................................................................................. 10 2.3.10 Exchange Market............................................................................................ 10 XML output.............................................................................................................. 10 Changes.................................................................................................................. 11 2.3.11 Market.............................................................................................................. 11 XML output.............................................................................................................. 11 2.3.12 Industries......................................................................................................... 11 2.3.13 War.................................................................................................................. 12 XML output.............................................................................................................. 12 Changes.................................................................................................................. 12 2.3.14 Battle............................................................................................................... 12 XML output.............................................................................................................. 13 2.3.15 Battle by war....................................................................................................13 2.3.16 Battle combatants............................................................................................13 2.4 Authorized calls.........................................................................................................13 2.4.1 Registering your application.............................................................................. 14 2.4.2 Application states............................................................................................... 15 2.4.3 OAuth URLs...................................................................................................... 16 2.4.4 Return Types..................................................................................................... 16 2.4.5 Citizen info.........................................................................................................16
Page 2/17
1 Introduction
1.1 Welcome to the eAPI!
Welcome to the eRepublik Application Programming Interface (API) documentation! The purpose of the document is to give you an overview of the features of the eRepublik API (hereafter referred to as eAPI). The eAPI can be used to retrieve data from the eRepublik.com game in application-friendly formats like XML and JSON and also offers functions to interact with the game's ecosystem. For comments or suggestions, write an email to api at eRepublik.com.
1.2.2 Uses
The eAPI is a language and platform agnostic set of http services that can be used to build third party applications around eRepublik. The current eAPI can be separated into 3 major categories: Data retrieval: You can retrieve information about citizens, companies, wars and similar entities on eRepublik. The data will be returned in either XML or JSON data formats. These functions are available to the public and may be used without any authorization or registration. User authentication: eRepublik users can authenticate themselves to your application using their eRepublik citizen account credentials without having to hand out these credentials. You can therefore build secure applications which require its users to authenticate them as eRepublik citizens.
1.2.3 OAuth
For functions where security plays an important role, like the user authentication process, the eAPI uses a mechanism called OAuth in version 1.0a. OAuth is a renowned standard for secure authentication which is used by many sites on the Internet. If you are familiar with OpenID, you pretty much already know how to use OAuth.
Page 3/17
There are ready-to-use modules and libraries for OAuth for most programming languages out there, so instead of telling you how to implement OAuth yourself, we'd like to point you to http://oauth.net/code/ for a list of these modules and encourage you to use them. For more (or all) information on OAuth, visit the official webpage at http://oauth.net/. Note: in contrast to the first version of the eAPI, the current eAPI uses a newer and more secure version of the OAuth mechanism. It requires your application to receive an optional token verif ier at the callback URL and pass it to the exchange request token for access token OAuth call.
2 Getting started
The eAPI consists of two types of calls: feeds and authorized calls. Feeds are simple resources that can be requested directly without any authorization. Example: point your browser to
http://api.erepublik.com/v2/feeds/countries
to get an XML list of all countries. In order to use authorized calls like citizen authorization, you first need to register your application with the eAPI at http://api.erepublik.com/apps (for more information, see Authorized calls). You will get an OAuth key and OAuth secret to securely sign these types of requests.
http://api.erepublik.com/v2/feeds/countries/1.json
Page 4/17
All the below examples will deal with XML data because it's more human readable. Feel free to always use the JSON format if you prefer it!
2.2 Errors
When the eAPI encounters an error, it will usually return an error element containing a time and a message element. Calling the following url
http://api.erepublik.com/v2/feeds/countries/10000
These errors are meant for debugging purposes only, so if the eAPI returns such a response, the only information for your application should be there was an error - do not use the message for anything other than reading it yourself.
2.3 Feeds
The eAPI data feeds let you retrieve various information about the game. No registration or authentication is required to use the feeds. To use a feed, simply make an HTTP GET request to the appropriate url.
2.3.2 Citizen
Returns information about one citizen. The citizen can be retrieved by either his/her id or his/her citizen name. The name parameter of the citizen_by_name call is not case sensitive. Note that for the citizen_by_name call, you have to specify the format (either xml or json) before the name parameter. URLs:
http://api.erepublik.com/v2/feeds/citizens/<id> http://api.erepublik.com/v2/feeds/citizen_by_name/<format>/<name>
Examples:
http://api.erepublik.com/v2/feeds/citizens/1450324
returns information about the citizen with the id 1450324 in xml format.
http://api.erepublik.com/v2/feeds/citizen_by_name/json/calaveradeluxe
returns information about the citizen with the name calaveradeluxe in json data format. The format parameter is not optional. Page 5/17
Note that citizen names can contain special characters, you should therefore always URL escape the name before making the request, replacing all special characters with their corresponding URL escape code. The name fresh!==!dude would become fresh %21%3D%3D%21dude. Otherwise, the eAPI will not recognize some names. XML output
<citizen> <residence> <citizenship> <is-general-manager> <party> <medals> <medal> </medals> ... </citizen>
describes the location where this citizen currently remains describes the country this citizen belongs to contains true if the citizen owns a company describes the party(name, id and is-president) this citizen belongs to Empty if not in a party contains the type of the medal and the amount of medal that have been acquired
Changes Changed citizenship to contain a region tag and a country tag. Added residence tag, containing a country and a region tag. Removed country, country-id, region and region-id. This information is now found in the residence tag. Moved fights, damage and military-rank into the military tag. Renamed military-rank to rank. Renamed fights to fight-count. Changed skills to contain the skill id, the skill name and the points in that skill. Removed friends tag.
Examples:
http://api.erepublik.com/v2/feeds/countries/1/citizens.xml.gz
returns information about the country citizens with the country id 1 in xml format.
Page 6/17
XML output
<citizens> <citizen> <residence> <citizenship> <is-general-manager> <party> <medals> <medal> </medals> ... </citizen> </citizens>
describes the location where this citizen currently remains describes the country this citizen belongs to contains true if the citizen owns a company describes the party(name, id and is-president) this citizen belongs to Empty if not in a party contains the type of the medal and the amount of medal that have been acquired
2.3.4 Countries
Returns information about all countries. URL:
http://api.erepublik.com/v2/feeds/countries
Changes Instead of just a brief summary, this call now returns a list of fully fetched countries. For the v2 changes made to one country, see the country call.
2.3.5 Country
Returns information about one country by its country id. For detailed information about the regions of a country, see regions by country. For detailed information about the wars a country is involved in, see wars by country. URL:
http://api.erepublik.com/v2/feeds/countries/<id>
Example:
http://api.erepublik.com/v2/feeds/countries/1
Page 7/17
XML output
<country> <region-count> <regions> <region> </regions> <citizen-count> <citizen-fee> </country>
the number of regions this country has contains a short description of all regions this country has contains the name and id of the region the number of alive citizens in this country the amount of money a new citizen gets, see http://wiki.erepublik.com/index.php/Citizen_fee for more information
Changes Removed permalink. Renamed total-citizens to citizen-count. Removed permalink from regions. Removed new-citizens-today. Renamed initials to code. Renamed number-of-regions to region-count.
2.3.6 Region
Returns information about one region by its globally unique region id. To get information about the citizens/inhabitants of a region, see citizens by region. URL:
http://api.erepublik.com/v2/feeds/regions/<id>
Example:
http://api.erepublik.com/v2/feeds/regions/9
XML output
<region> <buildings> <defense-systems> <defense-system> </defense-systems> <hospitals> <hospital> </hospitals> </buildings> <citizen-count> </region>
contains info about all defense-systems in the region contains info about one defensive-system with area-of-effect, durability, defense-bonus and customization-level contains info about all hospitals in the region contains info about one hospital with area-of-effect, wellness-budget, maxheal-per-citizen and customization-level the number of alive citizens in the region
Page 8/17
eRepublik API documentation v0.6 Note that this is only an excerpt of the region feed.
Changes Removed citizens, for information about the citizens of a region, see citizens by region. Renamed population to citizen-count. Renamed constructions to buildings. Removed name and permalink from neighbours. Removed permalink.
Example:
http://api.erepublik.com/v2/feeds/countries/1/regions
Example:
http://api.erepublik.com/v2/feeds/countries/1/wars
Returns all wars that the country with the id 1 is involved in.
Page 9/17
http://api.erepublik.com/v2/feeds/regions/<id>/citizens/<page>
Example:
http://api.erepublik.com/v2/feeds/regions/9/citizens/0
Returns page 1 (first page) of the list of citizen-ids that are living in the region with id 9.
2.3.10 Company
Returns information about one company. URL:
http://api.erepublik.com/v2/feeds/companies/<id>
Example:
http://api.erepublik.com/v2/feeds/companies/182533
XML output
<company> <customization> <employees> <employee> </employees> <job-offers> <job-offer> </job-offers> </company>
contains the attributes that the products of this company modify. The attributes are dependent on the industry the company is working in contains all citizens that are employed at this company contains the name, id and country(citizenship) of the citizen contains all job-offers of this company contains info about one job offer with the number-of-jobs, skill-id, required-skill, salary and industry
Changes Domain has been replaced by industry. Quality has been replaced by customization level. Added customization.
http://api.erepublik.com/v2/feeds/exchange/<buy_currency>/<sell_currency>
buy_currency: The currency that you want to buy. sell_currency: The currency that you want to sell. Example:
http://api.erepublik.com/v2/feeds/exchange/RON/GOLD
Returns the 10 best offers that sell you RON for GOLD.
XML output
<offers> <offer> <amount> <exchange-rate> <seller> </offer> </offers>
contains info about one exchange offer the a amount of money that is offered the exchange-rate of the two currencies. This is what you would need to pay for one unit of the offered money contains either a citizen or a company with their name and id
2.3.12 Market
The market feed provides information about product offers, filtered by their attributes. URL:
http://api.erepublik.com/v2/feeds/market/<industry_id>/<country_id>/<attr_1>/<attr_2>/<a ttr_3>/<attr_4>
industry_id: The id of the industry in which you want to look for products. See the industries feed for information about the industry ids. country_id: the id of the country in which you want to look for products. attr_1 attr_4: These correspond to the attributes of the product and state the minimum value the product should have at this attribute. Products have different number of attributes (0 to 4), and you must specify the correct number. The order of the attributes is the order they are returned in the industries feed. Example:
http://api.erepublik.com/v2/feeds/market/1/39/10/20
will return the best 10 offers of food (industry_id 1) in Finland (country_id 39) which has at least 10 wellness and 20 happiness. Adding a third attribute to the call would return an error because the food industry's products have only these 2 attributes.
Page 11/17
XML output
<offers> <offer> <customization> </offers> </offers>
contains info about one market offer contains the attributes that this product modifies. The attributes are dependent on the industry this product belongs to
2.3.13 Industries
Returns Information about all industries and their customizable attributes. The attributes are returned in the same order the market feed takes them. URL:
http://api.erepublik.com/v2/feeds/industries
2.3.14 War
Returns information about one war. For detailed information on the battles fought in this war, see battle by war. URL:
http://api.erepublik.com/v2/feeds/wars/<id>
Example:
http://api.erepublik.com/v2/feeds/wars/91
Page 12/17
XML output
<war> <progress> <started-at> <finished-at> <finished-reason> </progress> <proclaimed-to> <allies> <ally> </allies> </proclaimed-to> <proclaimed-by> <allies> <ally> <allies> </proclaimed-by> <battles> </war>
contains the date when the war was started. Is always set contains the date that the war finished, empty if the war is still in progress contains the reason why the war ended. Can be PEACE_DECLARED or CONQUERED, empty if the war is still in progress contains name, id and code of the country that this war was declared to contains a list of allies the country has describes an ally with id, name and code contains name, id and code of the country that declared the war contains a list of allies the country has describes an ally with id, name and code contains a list battles with their id
2.3.15 Battle
Returns information about a battle. For information on the combatants fighting in the battle, see combatants. URL:
http://api.erepublik.com/v2/feeds/battles/<id>
Example:
http://api.erepublik.com/v2/feeds/battles/1
XML output
Note that this is only an excerpt of the battle feed.
Page 13/17
contains the date when the battle was started. Is always set contains the date when this battle finished. Empty if the battle is still in progress contains the reason why the battle was finished. Can be TIME_LIMIT_REACHED, PEACE_DECLARED, HAS_WINNER, RETREAT or CONQUERED
</progress> </battle>
Example:
http://api.erepublik.com/v2/feeds/wars/639/battles
Example:
http://api.erepublik.com/v2/feeds/battles/1/combatants/2
Returns page 3 of the combatants that fought in the battle with the id 1.
Page 14/17
After you have logged in, click on register a new application. You'll need to provide: The name of your application A short description of what your application does The main URL of your application An optional support URL where your users can get help with your application A callback URL (after authorizing or denying your request, the user will be redirect to this url with the OAuth token and (new to v1 users!) the OAuth token verif ier)
Page 15/17
After registering your application, you will see a detailed summary. Here you will find your consumer key and your consumer secret. You will need both of them to make authenticated calls to the eAPI. You can always see your consumer key and consumer secret later by logging to the eAPI at http://api.erepublik.com/apps and clicking on the name of your application. WARNING: Do not share the consumer secret with anyone. It allows everyone to forge requests on your behalf.
Page 16/17
Once you requested live state, the eAPI team will review your request and approve or reject your application. When approved, you may switch your application's state from sandboxed to live and also vice versa at any time. Note that if you switch back from live to sandboxed state and edit your application's details, any former approval will be revoked and your application needs to be approved again!