Overview

Folders help you organize materials into logical groups. You can:
  • Create folders and subfolders
  • Move materials between folders
  • Rename and delete folders
  • List folder contents
  • Create nested folder structures

Folder Object

{
  "_id": "folder_123abc",
  "name": "Biology Notes",
  "organizationId": "org_456def",
  "parentId": null, // null for root folders
  "materialCount": 15,
  "subfolderCount": 3,
  "path": "/Biology Notes",
  "status": "active",
  "createdAt": "2024-01-15T10:00:00Z",
  "updatedAt": "2024-01-15T10:00:00Z"
}

Create Folder

Create a new folder to organize your materials.
// Create a root folder
const folder = await client.v1.folders.create({
  name: 'Biology Course',
  parentId: null // Optional, null for root folder
});

// Create a subfolder
const subfolder = await client.v1.folders.create({
  name: 'Chapter 1 - Cell Structure',
  parentId: folder._id
});

console.log('Folder created:', folder._id);
console.log('Subfolder path:', subfolder.path);

List All Folders

Get all folders in your organization.
// Get all folders
const folders = await client.v1.folders.list();

// Get only root folders
const rootFolders = await client.v1.folders.list({
  parentId: null
});

// Get subfolders of a specific folder
const subfolders = await client.v1.folders.list({
  parentId: 'folder_123abc'
});

console.log(`Found ${folders.length} total folders`);

Get Folder Details

Retrieve details about a specific folder including material and subfolder counts.
const folder = await client.v1.folders.get('folder_123abc');

console.log('Folder name:', folder.name);
console.log('Materials:', folder.materialCount);
console.log('Subfolders:', folder.subfolderCount);
console.log('Path:', folder.path);

Rename Folder

Change the name of an existing folder.
const renamedFolder = await client.v1.folders.rename('folder_123abc', {
  name: 'Biology Course - Updated'
});

console.log('Folder renamed to:', renamedFolder.name);
console.log('New path:', renamedFolder.path);

Move Folder

Move a folder to a different parent folder or to the root level.
// Move to another folder
const movedFolder = await client.v1.folders.move('folder_123abc', {
  parentId: 'folder_456def'
});

// Move to root level
const rootFolder = await client.v1.folders.move('folder_123abc', {
  parentId: null
});

console.log('Folder moved to:', movedFolder.path);

Delete Folder

Delete a folder. You can choose to move materials to another folder or delete them.
// Delete folder and move materials to another folder
await client.v1.folders.delete('folder_123abc', {
  moveMaterialsTo: 'folder_456def'
});

// Delete folder and move materials to root
await client.v1.folders.delete('folder_123abc', {
  moveMaterialsTo: null
});

// Delete folder and all its materials (use with caution!)
await client.v1.folders.delete('folder_123abc', {
  deleteAllMaterials: true
});

console.log('Folder deleted successfully');

Get Folder Contents

List all materials in a specific folder.
// Get materials in a folder
const materials = await client.v1.materials.list({
  folderId: 'folder_123abc'
});

console.log(`Folder contains ${materials.length} materials`);

// Display material names
materials.forEach(material => {
  console.log(`- ${material.name} (${material.contentType})`);
});

Example: Complete Folder Organization

Here’s a complete example of organizing course materials:
// 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',
  parentId: courseFolder._id
});

const chapter2 = await client.v1.folders.create({
  name: 'Chapter 2 - Genetics',
  parentId: 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({
  parentId: courseFolder._id
});

console.log(`Course folder: ${courseFolder.name}`);
subfolders.forEach(folder => {
  console.log(`  └─ ${folder.name}`);
});

// 5. Get materials in chapter 1
const chapter1Materials = await client.v1.materials.list({
  folderId: chapter1._id
});

console.log(`\nChapter 1 materials: ${chapter1Materials.length}`);