ENGAGE HELP CENTER
Engage API for data export
This section will be your guide on how to export data from the Engage platform with help of Engage API.
You need to have valid Engage API credentials to execute the Python script.

If you would like to use Engage API, please contact support@longenesis.com to receive the API credentials.
Longenesis.Engage provides API for eligible clients. Currently, downloading the participants' responses in JSON or EXCEL formats is supported.
Check the code sample provided below to see how to obtain the token, as well as download the export file.
Additionally, interactive API documentation is available here: https://engage-openapi.longenesis.com/docs.
Set up the "requests" library for the script
This script uses the popular requests library to make API calls.
First, set up virtual environment and install requests library.
python3 -m venv venv
source venv/bin/activate
pip install requests
Then run hello_world script.

python3 hello_world.py
A new file report_file.xlsx should now appear in the same folder.
NB! Skip this step if requests library already is in your Python path.
Run the Python script to export data
The following Python code snipped shows how to obtain auth token and download survey answers as Excel file.
import requests
AUTH_ENDPOINT = "https://auth.longenesis.com/realms/curator-engage/protocol/openid-connect/token"
USERNAME = "<your username>"
PASSWORD = "<your password>"
CLIENT_ID = "<Longenesis issued client id>"
CLIENT_SECRET = "<Longenesis issued client id>"
ENGAGE_ACTIVITY_ID = <activity ID>
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"]
response = requests.get(
    f"https://engage-openapi.longenesis.com/xlsx_answers/{ENGAGE_ACTIVITY_ID}",
    params={
        "include_all": True,
        "start_date": "2022-01-01",
        "end_date": "2022-01-31",
        "exclude_admins": False,
    },
    headers={"Authorization": f"Bearer {access_token}"},
)
with open("report_file.xlsx", "wb") as f:
    f.write(response.content)
Full API documentation is available here.