This guide explains how to retrieve an existing project or projects using the BlendDuck SDK.

Usage

To retrieve a project, you’ll use the projects.get() method of the BlendDuck client.

import BlendDuck from "@blendduck/node-sdk";

// Initialize the BlendDuck client
const client = new BlendDuck({
  apiKey: process.env.BLENDDUCK_API_KEY
});

async function retrieveProject(projectId: string) {
  // Retrieve the project
  const project = await client.projects.get(projectId);

  console.log(`Retrieved project: ${project.title}`);
  console.log(`Number of clips: ${project.clips.length}`);

  // You can now work with the project object
  // For example, you can access its properties:
  console.log(`Project aspect ratio: ${project.ratio}`);
  console.log(`Project theme: `, project.theme);
}

// Usage
retrieveProject("your-project-id-here");

To retrieve projects, you’ll use the projects.list() method

import BlendDuck from "@blendduck/node-sdk";

// Initialize the BlendDuck client
const client = new BlendDuck({
  apiKey: process.env.BLENDDUCK_API_KEY
});

async function retrieveProjects() {
  const { projects } = await client.projects.list();
  // equals
  // const { projects } = await client.projects.list({ page: 0, limit: 20 });
}

// Usage
retrieveProjects();

Error Handling

If the project cannot be found or there’s an issue with the API request, the method will throw an error. It’s good practice to wrap the call in a try-catch block to handle any potential errors gracefully.