pythonpython-requests

GraphQL API Querying


I am new to API's and am struggling to query it. I managed to get the below to work, but that is all.

query = """{
 player(slug:"nico-schlotterbeck") {
   firstName
   lastName
   position
   cardPositions
   id
   slug
   activeClub {
     name
   }
   age
   so5Scores(last:5) {
     score
   }
 }
}"""

The below does not seem to be working and I am unsure why?

query = """{
  card(slug:"nico-schlotterbeck") {
   assetId
 }
}"""

The link for the playground is https://api.sorare.com/graphql/playground


Solution

  • While card() accepts a slug, it is not a player.slug it is a card.slug so you need to find out valid data for your player:

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

    Will give you a list of all that players card slugs

    Alternatively, you can get them from player:

    {
      player(slug: "nico-schlotterbeck") {
        firstName
        lastName
        slug
        cards{nodes{slug}}
      }
    }
    

    From either we can file a bunch of card slugs like:

    "nico-schlotterbeck-2022-common-d60f209d-0e32-47a2-8e8d-1c2406cde20e"
    

    and using it was can query card

    {
      card(slug:"nico-schlotterbeck-2022-common-d60f209d-0e32-47a2-8e8d-1c2406cde20e") {
       assetId
     }
    }
    

    If what you seek are the assetId you can also directly get that from player:

    {
      player(slug: "nico-schlotterbeck") {
        firstName
        lastName
        slug
        cards{nodes{
          assetId
        }}
      }
    }