Search code examples
pythonjsonapiopensea

Getting a single Json value in python


I have this API response, I want to take some values and store them as variables for a python BOT for example 'floor_price' (I want the integer after it ofc) but for some reason, it's not working it keeps giving me errors but when I try it with 'stats' it works and gives everything.

The API https://api.opensea.io/api/v1/collection/ogcats-harvest-galaxy/stats

url = "https://api.opensea.io/api/v1/collection/ogcats-harvest-galaxy/stats"

 headers = {"Accept": "application/json"}

response = requests.request("GET", url)
json_response = response.json()
 floor= json_response['floor_price']

pls help :)


Solution

  • url = "https://api.opensea.io/api/v1/collection/ogcats-harvest-galaxy/stats"
    
    headers = {"Accept": "application/json"}
    
    response = requests.request("GET", url)
    json_response = response.json()
    floor= json_response['stats']['floor_price']
    

    credits: @kindall