This guide explains how to create a new project using the BlendDuck SDK.

Usage

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

import BlendDuck, { Project, Clip, Text, Animation, AnimationType } from "@blendduck/node-sdk";

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

async function createProject() {
  // Create a new project
  const project = new Project();
  project.title = "My New Video Project";
  project.ratio = "16:9";

  // Create a clip
  const clip = new Clip(5); // 5-second clip

  // Add a text element to the clip
  const textElement = new Text();
  textElement.text = "Hello, BlendDuck!";
  textElement.x = 960; // Center horizontally (assuming 1920x1080 resolution)
  textElement.y = 540; // Center vertically
  textElement.fontSize = 60;

  // Add a fade-in animation to the text
  const fadeIn = new Animation(AnimationType.FadeIn);
  fadeIn.startTime = 0;
  fadeIn.endTime = 1;
  textElement.addAnimation(fadeIn);

  // Add the text element to the clip
  clip.addElement(textElement);

  // Add the clip to the project
  project.addClip(clip);

  // Create the project on BlendDuck
  const projectId = await client.projects.create(project);

  console.log(`Project created successfully! ID: ${projectId}`);
  console.log(`Edit your project at: https://blendduck.com/editor/${projectId}`);
}

// Usage
createProject();
When creating a new project, there is at least one Clip in the Project.

Error Handling

If there’s an issue with creating the project or 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.