import requests
AUTH_ENDPOINT = (
"https://auth.longenesis.com/realms/curator-engage/protocol/openid-connect/token"
)
USERNAME = "<engage login email>" # use non-gmail account with sufficient permissions
PASSWORD = "<engage login password>"
CLIENT_ID = "<Longenesis issued client id>"
CLIENT_SECRET = "<Longenesis issued secret>"
ENGAGE_ORG_SLUG = "<orgagization slug>"
ENGAGE_ACTIVITY_SLUG = "<activity slug>"
access_token = requests.post(
AUTH_ENDPOINT,
data={
"username": USERNAME,
"password": PASSWORD,
"grant_type": "password",
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
},
).json()["access_token"]
data_for_import = {
"records": [
{
"participant": {
"participant_id": "string", # conditionally optional
"national_id": "123456-11111", # conditionally optional
"email": "participant@longenesis.com", # conditionally optional
"given_name": "John", # optional
"family_name": "Doe", # optional
"phone": "+371 22222222", # optional
"update_profile": true, # optional
"text": "Imported via API", # optional. A comment field that's displayed on patient's profile
},
"submission": {
"activity_slug": "abcdef",
"partner_item_id": "d-patient-1", # optional
"created_at": "2024-09-01 10:100", # optional
"answers": { # the question IDs as in your Engage survey
"question1": "abc",
"question2": "abc",
"question3": "abc"
},
},
}
]
}
response = requests.post(
f"https://engage-openapi.longenesis.com/submissions/{ENGAGE_ORG_SLUG}/bulk_post",
json=data_for_import,
headers={"Authorization": f"Bearer {access_token}"},
)
print(response.status_code)
print(response.json())