import os, httpx
API_KEY = os.environ["ONTORA_API_KEY"]
WORKSPACE_ID = os.environ["ONTORA_WORKSPACE_ID"]
client = httpx.Client(
base_url="https://api.ontora.com",
headers={"X-API-Key": API_KEY},
timeout=30.0,
)
# 1. Create the campaign shell
campaign = client.post("/v1/interviews", json={
"workspace_id": WORKSPACE_ID,
"name": "Q2 facility-ops interviews",
"goal": "Map current scheduling workflows and identify automation opportunities",
"channel": "in_app_chat",
"default_language": "en",
# Optional: schedule the send instead of emailing at launch
# "start_immediately": False,
# "timeframe_start": "2026-08-03",
# "timeframe_end": "2026-08-14",
# "timezone": "Europe/Berlin",
}).raise_for_status().json()
interview_id = campaign["id"]
print(f"Created campaign {interview_id}")
# 2. Add topics as question sets
client.post(f"/v1/interviews/{interview_id}/question-sets", json={
"name": "Daily scheduling",
"description": "Understand how shifts are assigned",
"sort_order": 0,
"topic_metadata": {"priority": "required", "sub_topics": ["Who decides", "Inputs used"]},
"questions": [
{"question_text": "Walk me through how this morning's shift assignment happened.",
"is_required": True},
{"question_text": "Rank these steps by how much time they cost you.",
"question_type": "ranking",
"component_config": {"items": [
{"id": "intake", "label": "Intake"},
{"id": "approval", "label": "Approval"},
]}},
],
}).raise_for_status()
# 3. Add contacts
client.post(f"/v1/interviews/{interview_id}/contacts/bulk", json={
"contacts": [
{"name": "Sam Rivera", "email": "sam@example.com", "department": "Operations"},
{"name": "Jess Thompson", "email": "jess@example.com", "department": "Operations"},
],
}).raise_for_status()
# 4. Start the campaign — sends (or schedules) the invitations
resp = client.post(f"/v1/interviews/{interview_id}/start").raise_for_status().json()
print(resp["message"])