Last active
January 27, 2022 08:42
-
-
Save tchak/6e0857fde811aa870ddf963c31151c4d to your computer and use it in GitHub Desktop.
GraphQL Request Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
token = "..." | |
dossierNumber = 123 | |
motivation = "..." | |
headers = { | |
'authorization': 'Bearer %s' % token, | |
'content-type': 'application/json' | |
} | |
getInstructeursForDossierQuery = """query getInstructeursForDossier($dossierNumber: Int!) { | |
dossier(number: $dossierNumber) { | |
id | |
instructeurs { | |
id | |
} | |
} | |
}""" | |
dossierAccepterQuery = """mutation dossierAccepter($input: DossierAccepterInput!) { | |
dossierAccepter(input: $input) { | |
dossier { | |
id | |
} | |
errors { | |
message | |
} | |
} | |
}""" | |
response = requests.post( | |
'https://www.demarches-simplifiees.fr/api/v2/graphql', | |
headers=headers, | |
json={ | |
'operationName': 'getInstructeursForDossier', | |
'query': getInstructeursForDossierQuery, | |
'variables': { 'dossierNumber': dossierNumber } | |
} | |
) | |
json = response.json() | |
dossierId = json['data']['dossier']['id'] | |
instructeurId = json['data']['dossier']['instructeurs'][0]['id'] | |
response = requests.post( | |
'https://www.demarches-simplifiees.fr/api/v2/graphql', | |
headers=headers, | |
json={ | |
'operationName': 'dossierAccepter', | |
'query': dossierAccepterQuery, | |
'variables': { | |
'input': { | |
'dossierId': dossierId, | |
'instructeurId': instructeurId, | |
'motivation': motivation | |
} | |
} | |
} | |
) | |
print(response.json()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
token = "..." | |
dossierNumber = 123 | |
query = """query getInstructeursForDossier($dossierNumber: Int!) { | |
dossier(number: $dossierNumber) { | |
id | |
instructeurs { | |
id | |
} | |
} | |
} | |
""" | |
response = requests.post( | |
'https://www.demarches-simplifiees.fr/api/v2/graphql', | |
headers={ | |
'authorization': 'Bearer %s' % token, | |
'content-type': 'application/json' | |
}, | |
json={ | |
'operationName': 'getInstructeursForDossier', | |
'query': query, | |
'variables': { 'dossierNumber': dossierNumber } | |
} | |
) | |
print(response.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment