// 1. Create main course folder
const courseFolder = await client.v1.folders.create({
name: 'Biology 101'
});
// 2. Create chapter folders
const chapter1 = await client.v1.folders.create({
name: 'Chapter 1 - Cells',
parentFolderId: courseFolder._id
});
const chapter2 = await client.v1.folders.create({
name: 'Chapter 2 - Genetics',
parentFolderId: courseFolder._id
});
// 3. Upload materials to specific folders
const fileBuffer = await fs.promises.readFile(
path.join(process.cwd(), 'cell-structure.pdf'),
);
const file = new File([fileBuffer], 'cell-structure.pdf', {
type: 'application/pdf',
});
const material = await client.v1.materials.upload.uploadFile({
file,
name: 'Cell Structure Notes',
folderId: chapter1._id
});
// 4. List folder structure
const subfolders = await client.v1.folders.list({
parentFolderId: courseFolder._id
});
console.log(`Course folder: ${courseFolder.name}`);
subfolders.forEach(folder => {
console.log(` └─ ${folder.name}`);
});
// 5. Get materials in chapter 1 with pagination
const chapter1Materials = await client.v1.materials.list({
folderId: chapter1._id,
limit: '20',
page: '1'
});
console.log(`\nChapter 1 materials: ${chapter1Materials.materials?.length || 0}`);
console.log(`Total in chapter: ${chapter1Materials.totalCount}`);
// Get next page if needed
if (chapter1Materials.totalPages && chapter1Materials.totalPages > 1) {
const page2 = await client.v1.materials.list({
folderId: chapter1._id,
limit: '20',
page: '2'
});
console.log(`Page 2 contains ${page2.materials?.length || 0} more materials`);
}