forum

API Problems

posted
Total Posts
3
Topic Starter
lwke
I have just started using APIv1 and wanted to check im using it correctly, (in python) as i cant seem to get it to work

My code looks like this


import requests
response = requests.get('https://osu.ppy.sh/forum/t/----/api/get_beatmaps/[MY CODE]')
print(response.status_code)
print(response.json())



The error looks like this



Traceback (most recent call last):
File "C:\Users\willi\PycharmProjects\osu!+\main.py", line 10, in <module>
print(requests.get('https://osu.ppy.sh/forum/t/----/api/get_beatmaps/[KEY]').json())
File "C:\Users\willi\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\willi\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\willi\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\willi\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)




Any help is appreciated, Im not even sure if this is the correct place to send this

Thanks
Death
You accidentally included your API key in the stack trace you provided. I recommend revoking it ASAP and getting a new one. As for your actual problem, you have a few issues:

The URL you are using for your request is wrong. I'm not really sure why you used a random forum thread, but all requests you make should just start with https://osu.ppy.sh/api/

After that, you need to choose one of the endpoints from https://github.com/ppy/osu-api/wiki and add it to the URL. In your case it looks like you want to use get_beatmaps, so the result would be https://osu.ppy.sh/api/get_beatmaps

And finally, you need to add the different options you want to use for you request as "query parameters". The options available to you are listed on that GitHub page I linked and they vary per endpoint. However, all of them require the parameter "k" with your API key as the value.

So an example of a full URL would look like this: https://osu.ppy.sh/api/get_beatmaps?k=API_KEY&s=100. If you replace "API_KEY" with your API key, it will return information for the beatmap with the ID 100.
Topic Starter
lwke

Death wrote:

You accidentally included your API key in the stack trace you provided. I recommend revoking it ASAP and getting a new one. As for your actual problem, you have a few issues:

The URL you are using for your request is wrong. I'm not really sure why you used a random forum thread, but all requests you make should just start with https://osu.ppy.sh/api/

After that, you need to choose one of the endpoints from https://github.com/ppy/osu-api/wiki and add it to the URL. In your case it looks like you want to use get_beatmaps, so the result would be https://osu.ppy.sh/api/get_beatmaps

And finally, you need to add the different options you want to use for you request as "query parameters". The options available to you are listed on that GitHub page I linked and they vary per endpoint. However, all of them require the parameter "k" with your API key as the value.

So an example of a full URL would look like this: https://osu.ppy.sh/api/get_beatmaps?k=API_KEY&s=100. If you replace "API_KEY" with your API key, it will return information for the beatmap with the ID 100.

Thanks so much, I didn't realise that I provided my API key, as you can probably tell, I've never worked with API before,
I just used a random URL in the post I don't know why though

Everything you have said makes a lot of sense and I will amend my code

Thanks again
Please sign in to reply.

New reply