Hi colleagues,
Could you please suggest the way how to connect using a pure Python/API to connect to the OHDSI Atlas and create a cohort using a JSON cohort file?
I used the code below to connect to the installed Broadsea image locally:
import requests
import json
cohort_json = json.loads(GENERATED_ANSWER_2[0])
ATLAS_URL = "http://127.0.0.1:80/WebAPI"
USERNAME = "XYZ"
PASSWORD = "XYZ"
session = requests.Session()
login_url = f"{ATLAS_URL}/user/login/db"
payload = {"login": USERNAME, "password": PASSWORD}
login_resp = session.post(login_url, data=payload)
print("Login:", login_resp.status_code)
print("Cookies now:", session.cookies.get_dict())
create_url = f"{ATLAS_URL}/cohortdefinition"
cohort_payload = {
"name": "My Cohort via Cookies",
"description": "Created using session cookies",
"expressionType": "SIMPLE_EXPRESSION",
"expression": cohort_json,
}
resp = session.post(create_url, json=cohort_payload)
print("Create cohort:", resp.status_code, resp.text)
It returns 200 for the login, and 401 for the cohort creating:
Login: 200
Cookies now: {}
Create cohort: 401
When I open that in my browser, I see the following:
Link: http://127.0.0.1/WebAPI/info
Response:
{âversionâ:â2.15.1â,âbuildInfoâ:{âartifactVersionâ:âWebAPI 2.15.1-SNAPSHOTâ,âbuildâ:âNAâ,âtimestampâ:âSat Aug 16 05:18:31 UTC 2025â,âbranchâ:â2.15.1â,âcommitIdâ:âba50f13aâ,âatlasRepositoryInfoâ:{âmilestoneIdâ:47,âreleaseTagâ:ââ},âwebapiRepositoryInfoâ:{âmilestoneIdâ:49,âreleaseTagâ:ââ}},âconfigurationâ:{âsecurityâ:{âsamlActivatedâ:false,âenabledâ:true,âsamlEnabledâ:false},âpluginsâ:{âatlasgisEnabledâ:false},âpersonâ:{âviewDatesPermittedâ:false},âheraclesâ:{âsmallCellCountâ:â5â}}}
Any help is very appreciated. I know, I may use wrappers on top of R packages, but I donât want to do it intentionally.
