Skip to content

Instantly share code, notes, and snippets.

@tchak
Last active January 27, 2022 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tchak/6e0857fde811aa870ddf963c31151c4d to your computer and use it in GitHub Desktop.
Save tchak/6e0857fde811aa870ddf963c31151c4d to your computer and use it in GitHub Desktop.
GraphQL Request Example
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())
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