Tribal wars public api?

Dracule Mihawk.

New Member
Reaction score
1
hello i have a question about tribalwars "api"


i dont manage to understand how twstats makes tools like this
http://www.twstats.co.uk/ukc1/index.php?page=map

cause noone of the public apis that are here :https://forum.tribalwars.us/index.php?threads/world-data.5996/)

offers data about to what tribe belongs each village

i asked my server Comunnity Manager and he tells me that twstats dosnt have any privileged info, so basically my conclusion is that the post is outdated/there are not all api calls information there?
 

JawJaw

Awesomest CM Ever
Tribal Wars Team
Community Management
Reaction score
1,575
It does contain that information, though.

Village information contains:
$village_id, $name, $x, $y, $player_id, $points, $rank

With $player_id, you can link it to player information, which contains:
$player_id, $name, $tribe_id, $villages, $points, $rank

And then just use tribe_id to get the tribe name:
$tribe_id, $name, $tag, $members, $villages, $points, $all_points, $rank

So basically you can use some INNER JOIN 's, if you're tech savvy and know SQL, to figure it out.
 

misteralb

Non-stop Poster
Tribal Wars Team
Script Moderator
Reaction score
272
The publicly available world data is composed from a set of text files (probably not the best of choices but thats fro another time to discuss).

There are:
- village.txt
- ally.txt
- player.txt
- etc...

With only these 3 you can get the list of players, villages and tribes on a world.

Now you ask how is it possible to list villages belonging to a tribe when neither ally.txt or village.txt does not directly make this connection.

Because entities or connected together like this.

Village -> Player -> Tribe

So you get a Tribe's player's list. Then for each Player you get its village's list, etc (all based on player id, tribe id, village id, etc).

All of this can be done as JawJaw said using JOINs in SQL or 2 separated SQL queries (dont see why not using JOIN's though other then the fact that they are usually hard to grasp for newer programmers).

Red.
 

Gregy

New Member
Reaction score
0
Hi
The publicly available world data is composed from a set of text files (probably not the best of choices but thats fro another time to discuss).

There are:
- village.txt
- ally.txt
- player.txt
- etc...
Can you developp the "etc..." ? :D

Is there any way to know conquests ? Ty
 

misteralb

Non-stop Poster
Tribal Wars Team
Script Moderator
Reaction score
272
Hello @Gregy ,

Yes it is possible to fetch conquests too from this endpoint:
Code:
/map/conquer.txt
/map/conquer.txt.gz (this is recommended whenever possible)
(Includes all conquered villages since start of the world)

This endpoint gives back a response following this format:
$village_id, $unix_timestamp, $new_owner, $old_owner

Also if you need only conquests from a specific time:
Code:
/interface.php?func=get_conquer&since=unix_timestamp
(This function allows to see the last conquered villages since the last Unix timestamp. The timestamp can go back 24 hours max.)

The reponse format is the same as above:
$village_id, $unix_timestamp, $new_owner, $old_owner

Hope this helps.
 

DaWolf85

Senior In-Game Staff
Tribal Wars Team
Senior
Team
Reaction score
498
Full list of possible endpoints, plus data structuring where necessary:
Code:
/map/village.txt
/map/village.txt.gz
(Data: id, name, x, y, player, points, rank)

/map/player.txt
/map/player.txt.gz
(Data: id, name, ally, villages, points, rank)

/map/ally.txt
/map/ally.txt.gz
(Data: id, name, tag, members, villages, points, all_points, rank)

/map/conquer.txt
/map/conquer.txt.gz
(Data: village_id, unix_timestamp, new_owner, old_owner)

/map/kill_att.txt
/map/kill_def.txt
/map/kill_sup.txt
/map/kill_all.txt
(Data: rank, id, kills)

/map/kill_att_tribe.txt
/map/kill_def_tribe.txt
/map/kill_all_tribe.txt
(Data: rank, id, kills)

/interface.php?func=get_conquer&since=unix_timestamp
(Data: village_id, unix_timestamp, new_owner, old_owner)
(NOTE: unix_timestamp value can be no more than 24 hours ago)

/interface.php?func=get_config

/interface.php?func=get_unit_info

/interface.php?func=get_building_info
Rules for using this data:
- It is recommended to pull the .gz version if possible.
- With the exception of the get_conquer function, these are updated once per hour, and thus should not be requested more frequently (users who ignore this risk being banned from the endpoints).

It is also worth noting that some older players/script creators may remember a profile.txt endpoint. This has been removed due to GDPR. It is no longer possible to pull profile data.