In this example, we will randomize (or 'shuffle') the phase seeding for a phase in an event. This is useful for tournament organizers who want to have a 'random seeding' event.
NOTE: You will need an API auth token belonging to a user who has admin permissions for your tournament.
The 3 basic steps for this are:
- Acquire current
seedMapping
via GQL query - Shuffle that seeding to create a new
seedMapping
- Post that new
seedMapping
via GQL mutation
In my example here, I use one Python script to perform all three of these actions.
from graphqlclient import GraphQLClientimport jsonimport random## Make sure to run `pip install graphqlclient`phaseId = YOUR_PHASE_IDauthToken = 'YOUR_AUTH_TOKEN'apiVersion = 'alpha'client = GraphQLClient('https://api.start.gg/gql/' + apiVersion)client.inject_token('Bearer ' + authToken)## Obtain Current SeedinggetSeedsResult = client.execute('''query getCurrentSeeds($phaseId:ID!){phase(id:$phaseId){seeds(query:{perPage: 100}){nodes{idseedNum}}}}''',{"phaseId":phaseId})resData = json.loads(getSeedsResult)if 'errors' in resData:print('Error:')print(resData['errors'])if not resData['data']['phase']:print('Phase not found')## Shuffle Current Seedingelse:print('Current seeding acquired...')seedMapping = []for key, value in enumerate(resData['data']['phase']['seeds']['nodes']):seedId = value['id']seedNum = value['seedNum']seedMapping.append({"seedId": seedId,"seedNum": seedNum,})## Put the new seeding herenewSeedMapping = []## Collect the seedIds here and then shuffle themseedIds = []for key, value in enumerate(seedMapping):seedIds.append(value['seedId'])random.shuffle(seedIds)## Build the new seeding map with the shuffled seedIdsfor key, value in enumerate(seedMapping):seedNum = key + 1newSeedMapping.append({"seedId": seedIds[key],"seedNum": seedNum})numSeeds = len(seedMapping)print("Randomizing " + str(numSeeds) + " seeds in phase " + str(phaseId) + "...")## Post the shuffled seeding via GQL MutationseedingUpdateResult = client.execute('''mutation UpdatePhaseSeeding ($phaseId: ID!, $seedMapping: [UpdatePhaseSeedInfo]!) {updatePhaseSeeding (phaseId: $phaseId, seedMapping: $seedMapping) {id}}''',{"phaseId": phaseId,"seedMapping": newSeedMapping,})resData = json.loads(seedingUpdateResult)if 'errors' in resData:print('Error:')print(resData['errors'])else:print('Success!')
Checking the seeding on start.gg
Here was my seeding before running my script:
As expected, my seeding afterwards is completely different!