Skip to main content

Session Archive Retrieval

After a session is complete, you can export all of its processed data as a single ZIP archive. Archives can optionally include the videos captured during recording.

Archive preparation happens asynchronously—you request it, poll until it's ready, then download the ZIP.

Performance considerations

Including videos significantly increases preparation time, especially for sessions with many activities. Only request videos if necessary.

Requesting an Archive

let archive = try await client.prepareArchive(for: session)
print("Archive task started:", archive.id)

To include videos, pass withVideos: true:

let archive = try await client.prepareArchive(for: session, withVideos: true)

Monitoring Archive Preparation

Poll archiveStatus until the status is ready:

var status: ArchiveStatus = .processing

while case .processing = status {
print("Archive being prepared...")
try await Task.sleep(nanoseconds: 20_000_000_000) // 20 seconds
status = try await client.archiveStatus(for: archive)
}

switch status {
case .ready:
print("Archive ready to download")
case .failed:
print("Archive preparation failed")
default:
break
}

Downloading the Archive

Once the status is ready, download the ZIP data:

if case .ready = status {
let zipData = try await client.archiveData(for: archive)
try zipData.write(to: URL(fileURLWithPath: "session-archive.zip"))
print("Archive saved:", zipData.count, "bytes")
}

Complete Example

// Request archive (with videos)
let archive = try await client.prepareArchive(for: session, withVideos: true)

// Wait for preparation to complete
var archiveStatus: ArchiveStatus = .processing
while case .processing = archiveStatus {
try await Task.sleep(nanoseconds: 20_000_000_000)
archiveStatus = try await client.archiveStatus(for: archive)
}

// Download
guard case .ready = archiveStatus else {
print("Archive preparation failed")
return
}

let zipData = try await client.archiveData(for: archive)
try zipData.write(to: URL(fileURLWithPath: "session-archive.zip"))
print("Archive saved:", zipData.count, "bytes")

Error Handling

do {
let archive = try await client.prepareArchive(for: session)
// Poll and download...
} catch {
print("Archive error: \(error)")
}