Skip to content

Instantly share code, notes, and snippets.

@revolunet
Created November 20, 2020 15:21
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 revolunet/7ffb46587b843a3c2ae227b5debe5e56 to your computer and use it in GitHub Desktop.
Save revolunet/7ffb46587b843a3c2ae227b5debe5e56 to your computer and use it in GitHub Desktop.
Python fetch dossiers demarches simplifiées
#
# Fetch les 100 premiers dossiers d'une démarche DS
#
# usage: DS_TOKEN=xyz python3 ds-fetch.py
#
import requests
import os
import json
DS_TOKEN = os.environ.get('DS_TOKEN')
API_URL = "https://www.demarches-simplifiees.fr/api/v2/graphql"
# requete GraphQL, a affiner sur https://www.demarches-simplifiees.fr/graphql
query = """
query getDemarches {
demarche(number: 12345) {
dateCreation
title
dossiers( first:100) {
edges {
node {
state
avis {
id
instructeur {
email
}
expert {
email
}
reponse
}
dateTraitement
dateDerniereModification
usager {
email
}
messages {
id
email
createdAt
body
}
datePassageEnInstruction
datePassageEnConstruction
number
motivation
champs {
id
label
stringValue
}
}
}
}
}
}
"""
def run_query(query):
headers = {"Authorization": "Bearer " + DS_TOKEN}
request = requests.post(API_URL, json={'query': query}, headers=headers, verify=False) # warn: SSL verification disabled
if request.status_code == 200:
return request.json()
else:
raise Exception("Query failed to run by returning code of {}. {}".format(request.status_code, query))
if __name__=="__main__":
result = run_query(query)
print(json.dumps(result, indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment