Is there a way to get a player's games using their username or to get their user ID using their username?

I’m working on an app that uses the OGS API to pull games for a given player. I’d like to have the app ask for a username from which to pull games, but I’m not aware of how to get a user ID from a username via the API. Is this possible? If so, how?

Another option would be to get the games using the username. Is this possible? I’m trying to avoid having users have to enter their password or their player ID for simplicity. Does anyone know if there’s a way to do this? Thank you!

2 Likes

Try playing around with this:

https://online-go.com/api/v1/players?username=Nealo

There’s also the api used for the search bar:

https://online-go.com/api/v1/ui/omniSearch?q=Nealo

Best of luck!

4 Likes

Keep in mind if you want to pull all the games of a user to be mindful of the servers load limits

5 Likes

Hey, shouldn’t be a problem if I limit the number of games (which I plan to). I’m curious if there’s is a parameter I can pass to limit the number of results? Seems the API documentation is still not up-to-date

3 Likes

Thanks, this should work!

3 Likes

That second one results in a “Not Found” page if I just plug it into a browser; I guess that kind of api call doesn’t return a json like the other one does? :stuck_out_tongue: That first one is super helpful tho thank <3

Would you happen to have any idea whether it’s especially load-heavy to just stop at using api/v1/players/{id}/games to get a complete list of games rather than to pull the full game data for each one?

2 Likes

Oops, typo - the link should work now!

If I had to guess, one call to /players/{player_id}/games is going to be less expensive than many calls to /games/{game_id}.

3 Likes

It still ends up being a fair number of calls, since it’s just 10 games per page, by default. I assume it won’t allow me to load, say, 1000 games on each page. (edit: though of course I haven’t actually tried :see_no_evil:)

Also this omnisearch thing is suuuuuper nifty! Thanks :smiley:

3 Likes

Any idea how to limit results? For example if I only wanted to pull 5 games from a given user? I was thinking maybe there was a variable I could pass to the API endpoint that does this. Do you know of one? Thanks again for the help

3 Likes

api/v1/players/{id}/games?ended__isnull=0&ordering=-ended&page_size=5

The only reason I know this is because of @shinuito’s answer to this exact question here - How to get the 5 most recent completed games for a user? - #2 by shinuito

5 Likes

Thank you, much appreciated!

2 Likes

I think page_size limit is 100, so only 10 requests to get to 1000 :slight_smile:

2 Likes

someone did make a tool for this

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.