forum

APIv2 - Get user beatmap score with mods parameter

posted
Total Posts
6
Topic Starter
Malai
Hi,

Recently started working on a small project that involves using osu! API v2 to collect user scores.
The program would use /beatmaps/{beatmap}/scores/users/{user} to get the user score on a given map with a given score modifier. Currently I see that the parameter "mods" is listed as TODO and requesting that always results in the same score being given, that is the highest score achieved by the user.

Is there a workaround currently available that I could use instead of using the aforementioned query?
From what I saw, I could use API v1 /api/get_scores with parameter "mods" to get the top 100 scores on the given map but this would not work well for popular maps and generally seems inefficient.

If the parameter "mods" in v2 is actually working but it's undocumented, could you please explain how to achieve the desired results?

Thanks in advance!
abraker
Stuff in v2 is working, but undocumented. Have you tried using v2 and see what it gives back?
Topic Starter
Malai
Yes and it's working to an extend.
I'm using python with "requests" library that allows me to send HTTP requests.
The following line is how I receive the score details:

score = requests.get(url = URL + f'beatmaps/{beatmap}/scores/users/{user}', headers = tokenheader, params = MapParams)

Where
  1. URL = "https://osu.ppy.sh/api/v2/"
  2. beatmap = ID of the beatmap I want to check, user = user ID
  3. tokenheader = the authentication token
  4. MapParams = {"mode": "osu", "mods": ????}
No matter what I put in the "mods" parameter I always receive the highest score achieved by the given user.
For example: I'm testing it on beatmapsets/636839#osu/1351114 where I have a nomod score as well as an EZ score. The response is available below, it's always my nomod score as it is higher on leaderboards compared to my EZ score:
{
    'position': 2442, 
    'score': {
         'id': 2751721782, 
         'user_id': 4863096, 
         'accuracy': 0.9387755102040817, 
         'mods': [], 
         'score': 74295050, 
         'max_combo': 2058, 
         'perfect': False, 
         'statistics': {
             'count_50': 2, 
             'count_100': 122, 
             'count_300': 1293, 
             'count_geki': 236, 
             'count_katu': 50, 
             'count_miss': 4
         }, 
         'rank': 'A', 
         'created_at': '2019-03-05T12:12:33+00:00', 
         'best_id': 2751721782, 
         'pp': 191.151, 
         'mode': 'osu', 
         'mode_int': 0, 
         'replay': False, 
         'beatmap': {
             'difficulty_rating': 5.8, 
             'id': 1351114, 
             'mode': 'osu', 
             'status': 'ranked', 
             'total_length': 307, 
             'version': 'Home Run', 
             'accuracy': 8.7, 
             'ar': 9.5, 
             'beatmapset_id': 636839, 
             'bpm': 175, 
             'convert': False, 
             'count_circles': 777, 
             'count_sliders': 643, 
             'count_spinners': 1, 
             'cs': 3.8, 
             'deleted_at': None, 
             'drain': 6, 
             'hit_length': 301, 
             'is_scoreable': True, 
             'last_updated': '2017-09-06T09:40:45+00:00', 
             'mode_int': 0, 
             'passcount': 655020, 
             'playcount': 9038421, 
             'ranked': 1, 
             'url': 'https://osu.ppy.sh/beatmaps/1351114'
         }, 
         'user': {
             'avatar_url': 'https://a.ppy.sh/4863096?1602285820.jpeg', 
             'country_code': 'PL', 
             'default_group': 'default', 
             'id': 4863096, 
             'is_active': True, 
             'is_bot': False, 
             'is_deleted': False, 
             'is_online': True, 
             'is_supporter': True, 
             'last_visit': '2021-02-27T17:16:07+00:00', 
             'pm_friends_only': False, 
             'profile_colour': None, 
             'username': 
             'Malai', 'country': {
                 'code': 'PL', 
                 'name': 'Poland'
             }, 
             'cover': {
                 'custom_url': 'https://assets.ppy.sh/user-profile-covers/4863096/37c84602e85283d861c003125429daf83999eeb790316e2f12802b8e103977d0.jpeg', 
                 'url': 'https://assets.ppy.sh/user-profile-covers/4863096/37c84602e85283d861c003125429daf83999eeb790316e2f12802b8e103977d0.jpeg', 
                 'id': None
             }
         }
    }
}

Additionally I tested if I pass the parameters correctly. To do that I tried changing "mode" to "mania" and it works just fine. Response 404 if I don't have any mania scores and 200 on maps that I passed on mania.

To sum things up: my goal is to get the best player score with a specific mod on a given map. Currently API v2 is always responding with the highest user score ignoring the parameter "mods".
abraker
fyi you can use [code] blocks for code. I fixed the entire post's formatting as it was hard to read

The mods parameter is indeed undocumented and there are no examples provided on how to use it. I recommend you request a top score that is modded as a way to reverse engineer what it expects.
Death
Try this:
https://osu.ppy.sh/api/v2/beatmaps/1351114/scores/users/4863096?mods[]=EZ

If you need multiple mods, I believe you need to append an extra mods[]= param for each mod, like this:
https://osu.ppy.sh/api/v2/beatmaps/1351114/scores/users/4863096?mods[]=EZ&mods[]=HD
Topic Starter
Malai
Firstly, thank you abraker for fixing the formatting.

Secondly, the solution you provided Death is working flawlessly! Thank you very much!
Please sign in to reply.

New reply