Skip to main content

Read Course Content

Read all content from a course — for example, to feed your course material into an AI model or your own systems. A course's content is a two-level hierarchy, and each level is a paginated list endpoint:

  • Activity — a section of a course. Two kinds: Topic (contains elements the learner completes) and Heading (a heading on the "View Course" page only — no further content)
    • Element — an individual piece of content (text, video, question, …)

API endpoints:

note

This example assumes you already have an access_token — see Authentication — and a course's course_user_id and course_id. You can find those for your course with the Read Course List endpoint (user_id and id on each course).

Read the activities in the course​

Read the published Topic activities. Omit kind to also include Heading activities (they contain no elements).

import httpx

BASE = "https://your-account.wyzed.com/v3_service/tenants"

# Activity schema: https://api3-dot-wyzed-app.appspot.com/docs#/schemas/ActivityDTO
response = httpx.get(
f"{BASE}/{tenant_id}/courses/{course_user_id}/{course_id}/activities/",
headers={
"Authorization": f"Bearer {access_token}",
},
params={
"limit": 100,
"is_published": True,
"kind": "Topic",
},
)
response.raise_for_status()
activities = response.json()["activities"]
print(f"found {len(activities)} activities")

Read the elements in each activity​

content = []
for activity in activities:
# Element schema: https://api3-dot-wyzed-app.appspot.com/docs#/schemas/ElementDTO
response = httpx.get(
f"{BASE}/{tenant_id}/courses/{course_user_id}/{course_id}"
f"/activities/{activity['id']}/elements/",
headers={
"Authorization": f"Bearer {access_token}",
},
params={
"limit": 100,
"is_published": True,
},
)
response.raise_for_status()
elements = response.json()["elements"]

content.append({
"id": activity["id"],
"name": activity["name"],
"elements": [
{
"id": e["id"],
"name": e["name"],
"description": e["description"],
"kind": e["kind"],
}
for e in elements
],
})
note

Both endpoints are cursor-paginated, but a single course rarely has more than 100 activities or elements, so one request per list is usually enough. If the response has "more": true, page through with the cursor as shown in List Users.

Element content by kind​

Each element kind stores its content differently in element["config"]. Pull out what you need per kind:

def element_body(element: dict) -> dict:
"""Extract the content of an element, depending on its kind."""
kind = element["kind"]
config = element["config"]

if kind == "TEXT":
# The HTML content of the text element.
return {"content": config["content"]}
elif kind in ("AUDIO", "CHAPTERED_VIDEO"):
# The uploaded media file. Keep the file_id — you need it to download
# the file (see "Downloading files" below).
file = config["file"]
return {"files": [{"file_id": file["file_id"], "filename": file["filename"]}]}
elif kind == "FILE_GROUP":
# A list of files. NOTE: file-group files use "id", not "file_id".
return {
"files": [
{"file_id": f["id"], "filename": f["filename"]}
for f in config["files"]
]
}
elif kind == "VIDEO":
# Either an uploaded video file, or a YouTube/Vimeo URL.
if config["file"]:
file = config["file"]
return {"files": [{"file_id": file["file_id"], "filename": file["filename"]}]}
elif config["video_url"]:
return {"video_url": config["video_url"]["url"]}
elif kind == "MULTIPLE_CHOICE":
# The multiple-choice options.
return {"choices": [a["title"] for a in config["answers"]]}
elif kind in ("LINK", "GOOGLE_DOC"):
# The URL of the link / embedded Google Doc.
return {"url": config["url"]}

# Other kinds (QUESTION, IMAGE, PRESENTATION, DISCUSSION, UPLOAD,
# SCORM, CODE, ...) carry no further text content.
return {}

The assembled content is a list of activities, each with its elements:

[
{
"id": 55,
"name": "Introduction",
"elements": [
{"id": 900, "name": "Welcome", "kind": "TEXT", "content": "..."},
...
]
},
...
]
tip

TEXT element content is HTML and can occasionally be very long (some embed images directly in the HTML). If you're feeding it to an AI model and hit size limits, strip <img> tags first.

Downloading files​

Files referenced by elements (the files lists above) are stored in the lms/course_content folder. Downloading is two steps: create a download URL using the file ID, then issue a GET request to that URL.

# A file referenced by an element (see "Element content by kind" above)
file_id = 456
filename = "example.mp4"

# 1. Create a download URL for the file
response = httpx.get(
f"https://your-account.wyzed.com/v3_file/tenants/{tenant_id}/files/{file_id}/download_url",
headers={
"Authorization": f"Bearer {access_token}",
},
params={
"folder": "lms/course_content",
},
)
response.raise_for_status()
download_url = response.json()["url"]

# 2. Download the file from that URL
response = httpx.get(download_url, follow_redirects=True, timeout=300)
response.raise_for_status()
with open(filename, "wb") as f:
f.write(response.content)
note

Download URLs are only valid for a short time (the response's expires_in_seconds tells you how long) — create them when you're ready to download, and don't store them.