Docs Guides
Content blocks
The six block types and the exact payload each one takes.
A lesson is an ordered list of typed blocks. The payload is validated against the type, and anything extra is rejected.
| Type | Send |
|---|---|
TEXT |
content: { "markdown": "…" } |
VIDEO |
assetId or content: { "url": "https://…" } |
IMAGE |
assetId, optional content: { "alt": "…" } |
FILE |
assetId (a downloadable file) |
EMBED |
content: { "url": "https://…", "height": 480 } |
ASSESSMENT |
assessmentId of a quiz in the same draft |
URLs must be https.
Text#
LESSON_ID=3d477cf4-98e8-48b4-997a-a370054d706c
curl -X POST "$LMS_URL/api/v1/lessons/$LESSON_ID/blocks" \
-H "X-API-Key: $LMS_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "TEXT",
"content": {
"markdown": "## Welcome\n\nStart here."
}
}'const LMS_URL = process.env.LMS_URL
const LMS_KEY = process.env.LMS_KEY
const lessonId = "3d477cf4-98e8-48b4-997a-a370054d706c"
const res = await fetch(`${LMS_URL}/api/v1/lessons/${lessonId}/blocks`, {
method: 'POST',
headers: { "X-API-Key": LMS_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
"type": "TEXT",
"content": {
"markdown": "## Welcome\n\nStart here."
}
}),
})
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`)
const data = await res.json()const LMS_URL = process.env.LMS_URL!
const LMS_KEY = process.env.LMS_KEY!
const lessonId = "3d477cf4-98e8-48b4-997a-a370054d706c"
const res = await fetch(`${LMS_URL}/api/v1/lessons/${lessonId}/blocks`, {
method: 'POST',
headers: { "X-API-Key": LMS_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
"type": "TEXT",
"content": {
"markdown": "## Welcome\n\nStart here."
}
}),
})
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`)
const data: unknown = await res.json()import os
import requests
LMS_URL = os.environ["LMS_URL"]
HEADERS = {"X-API-Key": os.environ["LMS_KEY"]}
lesson_id = "3d477cf4-98e8-48b4-997a-a370054d706c"
res = requests.post(f"{LMS_URL}/api/v1/lessons/{lesson_id}/blocks", headers=HEADERS, json={
"type": "TEXT",
"content": {
"markdown": "## Welcome\n\nStart here.",
},
}, timeout=10)
res.raise_for_status()
data = res.json()import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Request {
public static void main(String[] args) throws Exception {
String lmsUrl = System.getenv("LMS_URL");
String lmsKey = System.getenv("LMS_KEY");
String lessonId = "3d477cf4-98e8-48b4-997a-a370054d706c";
String body = """
{
"type": "TEXT",
"content": {
"markdown": "## Welcome\\n\\nStart here."
}
}
""";
var request = HttpRequest.newBuilder(URI.create(lmsUrl + "/api/v1/lessons/" + lessonId + "/blocks"))
.header("X-API-Key", lmsKey)
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString(body))
.build();
var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() >= 300) throw new IllegalStateException(response.statusCode() + " " + response.body());
System.out.println(response.body());
}
}require "net/http"
require "json"
lms_url = ENV.fetch("LMS_URL")
lesson_id = "3d477cf4-98e8-48b4-997a-a370054d706c"
uri = URI("#{lms_url}/api/v1/lessons/#{lesson_id}/blocks")
request = Net::HTTP::Post.new(uri, "X-API-Key" => ENV.fetch("LMS_KEY"), "Content-Type" => "application/json")
request.body = {
"type" => "TEXT",
"content" => {
"markdown" => "## Welcome\n\nStart here.",
},
}.to_json
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(request) }
raise "#{response.code} #{response.body}" unless response.is_a?(Net::HTTPSuccess)
data = JSON.parse(response.body)<?php
$lmsUrl = getenv('LMS_URL');
$lessonId = "3d477cf4-98e8-48b4-997a-a370054d706c";
$ch = curl_init("$lmsUrl/api/v1/lessons/{$lessonId}/blocks");
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['X-API-Key: ' . getenv('LMS_KEY'), 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
"type" => "TEXT",
"content" => [
"markdown" => "## Welcome\n\nStart here.",
],
]),
]);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) >= 300) {
throw new RuntimeException($response);
}
$data = json_decode($response, true);package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
)
func main() {
lessonId := "3d477cf4-98e8-48b4-997a-a370054d706c"
body := strings.NewReader(`{
"type": "TEXT",
"content": {
"markdown": "## Welcome\n\nStart here."
}
}`)
req, _ := http.NewRequest("POST", os.Getenv("LMS_URL") + "/api/v1/lessons/" + lessonId + "/blocks", body)
req.Header.Set("X-API-Key", os.Getenv("LMS_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
data, _ := io.ReadAll(res.Body)
if res.StatusCode >= 300 {
panic(fmt.Sprintf("%d %s", res.StatusCode, data))
}
fmt.Println(string(data))
}Uploaded media#
Upload once, then reference the asset:
First upload the file. The response has its id.
curl -X POST "$LMS_URL/api/v1/assets" \
-H "X-API-Key: $LMS_KEY" \
-F "file=@intro.mp4"import { openAsBlob } from 'node:fs'
const LMS_URL = process.env.LMS_URL
const LMS_KEY = process.env.LMS_KEY
const form = new FormData()
form.append("file", await openAsBlob("intro.mp4"), "intro.mp4")
const res = await fetch(`${LMS_URL}/api/v1/assets`, {
method: 'POST',
headers: { "X-API-Key": LMS_KEY },
body: form,
})
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`)
const data = await res.json()import { openAsBlob } from 'node:fs'
const LMS_URL = process.env.LMS_URL!
const LMS_KEY = process.env.LMS_KEY!
const form = new FormData()
form.append("file", await openAsBlob("intro.mp4"), "intro.mp4")
const res = await fetch(`${LMS_URL}/api/v1/assets`, {
method: 'POST',
headers: { "X-API-Key": LMS_KEY },
body: form,
})
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`)
const data: unknown = await res.json()import os
import requests
LMS_URL = os.environ["LMS_URL"]
HEADERS = {"X-API-Key": os.environ["LMS_KEY"]}
res = requests.post(f"{LMS_URL}/api/v1/assets", headers=HEADERS, files={"file": open("intro.mp4", "rb")}, timeout=10)
res.raise_for_status()
data = res.json()import java.io.ByteArrayOutputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.Path;
public class Request {
public static void main(String[] args) throws Exception {
String lmsUrl = System.getenv("LMS_URL");
String lmsKey = System.getenv("LMS_KEY");
String boundary = "----lms" + System.nanoTime();
var form = new ByteArrayOutputStream();
form.write(("--" + boundary + "\r\nContent-Disposition: form-data; name=\"file\"; filename=\"intro.mp4\"\r\n"
+ "Content-Type: application/octet-stream\r\n\r\n").getBytes());
form.write(Files.readAllBytes(Path.of("intro.mp4")));
form.write(("\r\n--" + boundary + "--\r\n").getBytes());
var request = HttpRequest.newBuilder(URI.create(lmsUrl + "/api/v1/assets"))
.header("X-API-Key", lmsKey)
.header("Content-Type", "multipart/form-data; boundary=" + boundary)
.method("POST", HttpRequest.BodyPublishers.ofByteArray(form.toByteArray()))
.build();
var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() >= 300) throw new IllegalStateException(response.statusCode() + " " + response.body());
System.out.println(response.body());
}
}require "net/http"
require "json"
lms_url = ENV.fetch("LMS_URL")
uri = URI("#{lms_url}/api/v1/assets")
request = Net::HTTP::Post.new(uri, "X-API-Key" => ENV.fetch("LMS_KEY"))
request.set_form([["file", File.open("intro.mp4")]], "multipart/form-data")
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(request) }
raise "#{response.code} #{response.body}" unless response.is_a?(Net::HTTPSuccess)
data = JSON.parse(response.body)<?php
$lmsUrl = getenv('LMS_URL');
$ch = curl_init("$lmsUrl/api/v1/assets");
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['X-API-Key: ' . getenv('LMS_KEY')],
CURLOPT_POSTFIELDS => ["file" => new CURLFile("intro.mp4")],
]);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) >= 300) {
throw new RuntimeException($response);
}
$data = json_decode($response, true);package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
var form bytes.Buffer
w := multipart.NewWriter(&form)
part, _ := w.CreateFormFile("file", "intro.mp4")
f, _ := os.Open("intro.mp4")
io.Copy(part, f)
w.Close()
req, _ := http.NewRequest("POST", os.Getenv("LMS_URL") + "/api/v1/assets", &form)
req.Header.Set("X-API-Key", os.Getenv("LMS_KEY"))
req.Header.Set("Content-Type", w.FormDataContentType())
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
data, _ := io.ReadAll(res.Body)
if res.StatusCode >= 300 {
panic(fmt.Sprintf("%d %s", res.StatusCode, data))
}
fmt.Println(string(data))
}Then add it to the lesson.
LESSON_ID=3d477cf4-98e8-48b4-997a-a370054d706c
curl -X POST "$LMS_URL/api/v1/lessons/$LESSON_ID/blocks" \
-H "X-API-Key: $LMS_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "VIDEO",
"assetId": "5b7e1d20-9c4f-4a38-8e16-2f0a6d9c3b47"
}'const LMS_URL = process.env.LMS_URL
const LMS_KEY = process.env.LMS_KEY
const lessonId = "3d477cf4-98e8-48b4-997a-a370054d706c"
const res = await fetch(`${LMS_URL}/api/v1/lessons/${lessonId}/blocks`, {
method: 'POST',
headers: { "X-API-Key": LMS_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
"type": "VIDEO",
"assetId": "5b7e1d20-9c4f-4a38-8e16-2f0a6d9c3b47"
}),
})
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`)
const data = await res.json()const LMS_URL = process.env.LMS_URL!
const LMS_KEY = process.env.LMS_KEY!
const lessonId = "3d477cf4-98e8-48b4-997a-a370054d706c"
const res = await fetch(`${LMS_URL}/api/v1/lessons/${lessonId}/blocks`, {
method: 'POST',
headers: { "X-API-Key": LMS_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
"type": "VIDEO",
"assetId": "5b7e1d20-9c4f-4a38-8e16-2f0a6d9c3b47"
}),
})
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`)
const data: unknown = await res.json()import os
import requests
LMS_URL = os.environ["LMS_URL"]
HEADERS = {"X-API-Key": os.environ["LMS_KEY"]}
lesson_id = "3d477cf4-98e8-48b4-997a-a370054d706c"
res = requests.post(f"{LMS_URL}/api/v1/lessons/{lesson_id}/blocks", headers=HEADERS, json={
"type": "VIDEO",
"assetId": "5b7e1d20-9c4f-4a38-8e16-2f0a6d9c3b47",
}, timeout=10)
res.raise_for_status()
data = res.json()import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Request {
public static void main(String[] args) throws Exception {
String lmsUrl = System.getenv("LMS_URL");
String lmsKey = System.getenv("LMS_KEY");
String lessonId = "3d477cf4-98e8-48b4-997a-a370054d706c";
String body = """
{
"type": "VIDEO",
"assetId": "5b7e1d20-9c4f-4a38-8e16-2f0a6d9c3b47"
}
""";
var request = HttpRequest.newBuilder(URI.create(lmsUrl + "/api/v1/lessons/" + lessonId + "/blocks"))
.header("X-API-Key", lmsKey)
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString(body))
.build();
var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() >= 300) throw new IllegalStateException(response.statusCode() + " " + response.body());
System.out.println(response.body());
}
}require "net/http"
require "json"
lms_url = ENV.fetch("LMS_URL")
lesson_id = "3d477cf4-98e8-48b4-997a-a370054d706c"
uri = URI("#{lms_url}/api/v1/lessons/#{lesson_id}/blocks")
request = Net::HTTP::Post.new(uri, "X-API-Key" => ENV.fetch("LMS_KEY"), "Content-Type" => "application/json")
request.body = {
"type" => "VIDEO",
"assetId" => "5b7e1d20-9c4f-4a38-8e16-2f0a6d9c3b47",
}.to_json
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(request) }
raise "#{response.code} #{response.body}" unless response.is_a?(Net::HTTPSuccess)
data = JSON.parse(response.body)<?php
$lmsUrl = getenv('LMS_URL');
$lessonId = "3d477cf4-98e8-48b4-997a-a370054d706c";
$ch = curl_init("$lmsUrl/api/v1/lessons/{$lessonId}/blocks");
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['X-API-Key: ' . getenv('LMS_KEY'), 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
"type" => "VIDEO",
"assetId" => "5b7e1d20-9c4f-4a38-8e16-2f0a6d9c3b47",
]),
]);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) >= 300) {
throw new RuntimeException($response);
}
$data = json_decode($response, true);package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
)
func main() {
lessonId := "3d477cf4-98e8-48b4-997a-a370054d706c"
body := strings.NewReader(`{
"type": "VIDEO",
"assetId": "5b7e1d20-9c4f-4a38-8e16-2f0a6d9c3b47"
}`)
req, _ := http.NewRequest("POST", os.Getenv("LMS_URL") + "/api/v1/lessons/" + lessonId + "/blocks", body)
req.Header.Set("X-API-Key", os.Getenv("LMS_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
data, _ := io.ReadAll(res.Body)
if res.StatusCode >= 300 {
panic(fmt.Sprintf("%d %s", res.StatusCode, data))
}
fmt.Println(string(data))
}Learners fetch files through the course, and only files their course version actually uses are served. See Files.
Quizzes in lessons#
Create the quiz first (Quizzes and questions), then add an ASSESSMENT block pointing at it. Set the lesson’s completionMode to ASSESSMENT_PASSED if passing should complete the lesson.
Changing a block#
PUT /blocks/{id} replaces its content. The type can’t change; delete the block and add another.