luchonacho
luchonacho

Reputation: 7167

How to list all parameters available to query via API?

As a end-point user of an API, how can I list all parameters available to pass the query? In my case (stats about Age of Empires 2 matches), the website describing the API has a list with some of them but it seems there are more available.

To provide more context, I'm extracting the following information:

GET("https://aoe2.net/api/matches?game=aoe2de&count=1000&since=1632744000&map_type=12")

but for some reason the last condition, map_type=12 does nothing (output is the same as without it). I'm after the list of parameters available, so I can extract what I want.

PD: this post is closely related but does not focus on API. Perhaps this makes a difference, as the second answer there seems to suggest.

Upvotes: 6

Views: 12955

Answers (2)

Chris
Chris

Reputation: 256

The documentation on their website is all any of us have to go by https://aoe2.net/#api

You can't just add your own parameters to the URL and expect it to return a value back as they have to have coded it to work that way.

Your best bet is to just extract as much data as you can by increasing the count parameter, then loop through the JSON response and extract the map_type from there.

JavaScript example:

<script>
json=[{"match_id":"1953364","lobby_id":null,"game_type":0},
{"match_id":"1961217","lobby_id":null,"game_type":0},
{"match_id":"1962068","lobby_id":null,"game_type":1},
{"match_id":"1962821","lobby_id":null,"game_type":0},
{"match_id":"1963814","lobby_id":null,"game_type":0},
{"match_id":"1963807","lobby_id":null,"game_type":0},
{"match_id":"1963908","lobby_id":null,"game_type":0},
{"match_id":"1963716","lobby_id":null,"game_type":0},
{"match_id":"1964491","lobby_id":null,"game_type":0},
{"match_id":"1964535","lobby_id":null,"game_type":12},];

for(var i = 0; i < json.length; i++) {
    var obj = json[i];

    if(obj.game_type==12){
        //do something with game_type 12 json object
        console.log(obj);
    }
}

</script>

Upvotes: 1

hilipati
hilipati

Reputation: 531

It is not possible to find out all available (undocumented) query parameters for a query, unless the API explicitly provides such a method or you can find out how the API server processes the query.

For instance, if the API server code is open source, you could find out from the code how the query is processed. Provided that you find the code also.

The answers in the post you linked are similarly valid for an API site as well as for one that provides content for a web browser (a web server can be both). Under the hood, there is not necessarily any difference between an API server or a server that provides web content (html) in terms of how queries are handled.

As for the parameters seemingly without an effect, it seems that the API in question does not validate the query parameters, i.e., you can put arbitrary parameters in the query and the server will simply ignore parameters that it is not specifically programmed to use.

Upvotes: 10

Related Questions