This guide explains how to update an existing project using the BlendDuck SDK.

Usage

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

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

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

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

  // Modify project properties
  project.title = "Updated Video Project";

  // Add a new clip
  const newClip = new Clip(3); // 3-second clip
  const newText = new Text();
  newText.text = "New content!";
  newText.x = 960;
  newText.y = 540;
  newText.fontSize = 48;

  const fadeIn = new Animation(AnimationType.FadeIn);
  fadeIn.startTime = 0;
  fadeIn.endTime = 1;
  newText.addAnimation(fadeIn);

  newClip.addElement(newText);
  project.addClip(newClip);

  const firstClip = project.clips[0];
  firstClip.duration = 6; // Change duration to 6 seconds

  // Modify an existing text element (assuming the first element is text)
  if (firstClip.elements.length > 0 && firstClip.elements[0].type === 'text') {
    const textElement = firstClip.elements[0] as Text;
    textElement.text = "Updated text content";
    textElement.fontSize = 72;
  }
  // Update the project on BlendDuck
  await client.projects.update(project);
  console.log(`Project updated successfully! ID: ${project.id}`);
  console.log(`Edit your updated project at: https://blendduck.com/editor/${project.id}`);
  
}

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

Error Handling

If there’s an issue with updating 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.