osu-api
osu-api copied to clipboard
Test api key
Is there a way to specifically testing the API key without querying maps or user information etc?
Something which just returns true or false whether a key is valid.
E.g. https://osu.ppy.sh/p/api/testkey.php?key=12321432313123213123
.
If you try to request anything with an invalid key, it'll return:
{"error":"Please provide a valid API key."}
, instead of the data.
So, I think you could just handle that in your code.
To add to @Eb3rM5 's point, the HTTP status code is 401 instead of 200, so you could also check for that.
https://osu.ppy.sh/api/get_user?k=a1b2c3d4e5f6g7h8a1b2c3d4e5f6g7h8
is my go-to check.
For anyone who's reading this now, a simple solution would be to check if there's a 401 response (adding to @gamescom15)
Example using Node.js request
module
request
.get('https://osu.ppy.sh/api/get_user?k=INVALIDKEYHERE',
function(err, response, body) {
// With this if statement do whatever you have to do to handle error
if(response == 401) console.log("No valid API key")
})