Skip to main content

Overview

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

Folder Object

{
  "_id": "folder_123abc",
  "name": "Biology Notes",
  "organizationId": "org_456def",
  "parentFolderId": 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',
  parentFolderId: undefined // Optional, null for root folder
});

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

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

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({
  parentFolderId: undefined
});

// Get subfolders of a specific folder
const subfolders = await client.v1.folders.list({
  parentFolderId: '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.retrieve('folder_123abc');

console.log('Folder name:', folder.name);
console.log('Materials:', folder.materialCount);
console.log('Subfolders:', folder.subfolders.length);
console.log('Parent folder:', folder.parentFolderId || 'root');

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', {
  parentFolderId: 'folder_456def'
});

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

console.log('Folder moved to:', movedFolder.parentFolderId || 'root');

Delete Folder

Delete a folder from your organization.
// Delete folder and move materials to another folder
await client.v1.folders.delete('folder_123abc');

console.log('Folder deleted successfully');

Get Folder Contents

List all materials in a specific folder.

Using materials.list()

// Get materials in a folder with pagination
const materials = await client.v1.materials.list({
  folderId: 'folder_123abc',
  limit: '20',
  page: '1'
});

console.log(`Folder contains ${materials.materials?.length || 0} materials`);
console.log(`Total in folder: ${materials.totalCount}`);

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

Using folders.listMaterials()

Alternatively, you can use the folders.listMaterials() method to get materials directly from a folder with pagination support.
// Get materials using folders.listMaterials() with pagination
const folderMaterials = await client.v1.folders.listMaterials(
  'folder_123abc',
  {
    limit: '20',
    page: '1'
  }
);

console.log(`Found ${folderMaterials.materials?.length || 0} materials`);
console.log(`Total: ${folderMaterials.totalCount}`);
console.log(`Page ${folderMaterials.page} of ${folderMaterials.totalPages}`);

// Iterate through all pages
if (folderMaterials.totalPages && folderMaterials.totalPages > 1) {
  for (let page = 2; page <= folderMaterials.totalPages; page++) {
    const nextPage = await client.v1.folders.listMaterials(
      'folder_123abc',
      { limit: '20', page: page.toString() }
    );
    console.log(`Page ${page}: ${nextPage.materials?.length || 0} materials`);
  }
}

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',
  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`);
}
I