sorare / api

Sorare API documentation
154 stars 49 forks source link

Requesting Card Prices #400

Open Luke1709 opened 1 year ago

Luke1709 commented 1 year ago

Hi,

I have attached the code below but it is only giving me assetId's for common cards

import requests
import json
import pandas as pd

# Set the API endpoint URL with the player ID in the URL path
url = "https://api.sorare.com/graphql/"

query = """{
  allCards(playerSlugs: ["nico-schlotterbeck"]) {
    nodes {
      slug
      player{slug}
      name
      rarity
    }
  }
}"""

query2 = """{
  card(slug:"0x0900f9d731ec42bc61f7bedbcd9aef6fc08679ed1b5c353788325e71600d5c69") {
    latestEnglishAuction {
          bestBid {
            amount
            amountInFiat { eur gbp usd }
 }
 }
 }
}"""

# Set the API key in a headers dictionary
headers = {
    "X-Api-Key": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
}

# Make a GET request to the API and print the response
r = requests.post(url, json ={'query': query}, headers=headers)
print(r)
json_data = json.loads(r.text)
df_data = json_data['data']
df = pd.DataFrame(df_data)

I believe it might be because of the API Key I have been given?

djizus commented 1 year ago

Hello @Luke1709 ,

You're requesting all cards (you can filter by rarity if you want to avoid getting common cards), and the api returns a maximum of 50 items at a time. I suggest you read this to learn how to browse all cards.