The MXKarma API controller is a simple REST-like API.
Some operations (such as submitting new karma scores) require an API key. A separate API key is required for each server.
An API key can be used to start a session, which yields you a session key, which is then a required parameter at some operations.
All responses are JSON-serialized objects of the following result:
All API requests should be submitted to https://karma.mania-exchange.com/api2/{methodName}?{parameters}.
POST requests are sometimes used if the data structure is more complex. The content of POST requests are always JSON-serialized.
The content-type has to be set to application/json
.
When used together with a controller, the following program flow should be followed to ensure performance:
Given server login and some additional information, creates a new session for the specified server. A session key and session seed are returned.
The session is not activated at time of creation, this has to be done using the session seed and api key in a following activateSession request.
Given a hash from the api key and session seed, and a session key obtained from startSession, activates the session for write operations. Once a session is succesfully activated, other activated sessions are closed. If a session failed to activate, the session is closed immediately.
Given a map its unique ID, a gamemode and titlepack, returns the amount of votes and the average vote.
An array of logins can be specified to get the ratings these players made, if any.
In case only the votes
result field is important, set the getvotesonly
value to true!
GetScriptName()
in case of a scripted mode. For hardcoded TrackMania modes, provide the suiting string from the set {Rounds
, TimeAttack
, Team
, Laps
, Cup
, Stunts
}.playerlogins
will be looked up. Should be true in case of requesting the values of e.g. newly joined players.getvotesonly
, this value equals -1.getvotesonly
, this value equals -1. Not per see integeral.
Given a map, gamemode, titlepack and an array of players who changed or added a new vote, saves the votes.
Note: Only changed votes should be submitted, do not send the whole collection of votes again!
Note: Make sure to call this method at reasonable times, such as once the map ends (EndMap callback) send all changed votes and not at every single vote!
Note: Only a single import per map per server is allowed, the client should track imports made as well!
Note: Only locally saved karma-imports are allowed!
GetScriptName()
in case of a scripted mode. For hardcoded TrackMania modes, provide the suiting string from the set {Rounds
, TimeAttack
, Team
, Laps
, Cup
, Stunts
}.
In case of an error, the success
field of the return object will be false and data
contains the following object:
Possible errors are listed below.
Code | Message & details | Thrown at |
---|---|---|
1 | internal server error Internal server error. | Anywhere |
2 | invalid session Session key is invalid (not activated, experied or got disabled). | activateSession, getMapRating, saveVotes |
3 | lacking parameters Some parameters are not provided. | startSession, activateSession |
4 | invalid api key API key not found or suspended. | activateSession |
5 | invalid server Server not found or suspended. | startSession, activateSession, saveVotes |
6 | server is banned Server is banned. | startSession |
7 | session origin and request mismatch Cross-server call rejected. | activateSession, getMapRating, saveVotes |
8 | invalid hash Invalid activation hash provided, session closed. | activateSession |
9 | session already activated Session already active. | activateSession |
10 | unsupported content-type Unsupported Content-Type. | getMapRating, saveVotes |
11 | too many logins Too many logins requested. | getMapRating |
12 | invalid format Invalid JSON or invalid structure. | getMapRating, saveVotes |
13 | votes rejected Malformed vote request. | saveVotes |
14 | no votes cast - please do not make requests if there are no votes! No votes cast. | saveVotes |
15 | too many import votes - request a limit raise if needed Too many imports. | saveVotes |
16 | import rejected Import rejected. | saveVotes |