Welcome @PedroReina, and thanks for your question. When you have a moment, we'd love to learn a bit about you and your project in the introduction thread!
If you happen to also be comfortable with R, I encourage you to check out ruODK which includes several notebook-style examples.
That said, I know there are many reasons to want to set up a Python-based pipeline. @Lindsay_Stevens_Au and I have just kicked off a project to make that easier and provide some worked examples.
To get a json document, you can use the OData data document:
{url}/v1/projects/{project}/forms/{formid}.svc/Submissions
If you have any repeats, you can replace Submissions
with the repeat name to get the json document for each repeat.
You also need to get a session token to be able to make the request. I recommend using a Project Viewer account for analysis.
If you use pandas
, you'll likely want to normalize the resulting json with a separator of /
to flatten groups.
Putting it all together:
import requests
import json
import pandas as pd
url = "https://"
project =
formid = ""
username = ""
password = ""
token_response = requests.post(
f"{url}/v1/sessions",
data=json.dumps({"email": username, "password": password}),
headers={"Content-Type": "application/json"},
)
token = token_response.json()["token"]
response = requests.get(
f"{url}/v1/projects/{project}/forms/{formid}.svc/Submissions?$filter=__system/reviewState ne 'rejected'",
headers={"Content-Type": "application/json", "Authorization": f"Bearer {token}"}
)
df = pd.json_normalize(response.json()['value'], sep='/')
You can also search the forum for various other Python-based examples (e.g. Error in GET request for Central API - #10 by yanokwa).