Skip to main content
PUT
https://api.pictory.ai
/
pictoryapis
/
v2
/
projects
/
{projectid}
Update Project
curl --request PUT \
  --url https://api.pictory.ai/pictoryapis/v2/projects/{projectid} \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: <content-type>'
{
  "success": true,
  "message": "Project updated successfully",
  "project": {
    "projectName": "Updated Project Name",
    "audioSpeed": 100,
    "videoVolume": 50,
    "scenes": [
      {
        "text": "Updated scene text",
        "sentence": [
          {
            "text": "Updated scene text",
            "highlight": true
          }
        ],
        "settings": {
          "hideText": false
        },
        "background": {
          "type": "image",
          "elementData": {
            "url": "https://new-media-url.com/image.jpg"
          }
        }
      }
    ]
  }
}

Overview

Update an existing project by sending the complete updated project object. This endpoint allows you to modify scene visuals, subtitle text content, scene settings, and other project attributes. The entire project object must be included in the request—partial updates are not supported.
Complete Object Required: You must send the entire project object in the request body, even if you’re only changing a few fields. Omitting fields may result in data loss or project corruption.
You need a valid API key to use this endpoint. Get your API key from the API Access page in your Pictory dashboard.

API Endpoint

PUT https://api.pictory.ai/pictoryapis/v2/projects/{projectid}

Request Parameters

Path Parameters

projectid
string
required
The unique identifier of the project to update. Can be either a string (for v3 schema projects) or an integer (for v2 schema and earlier projects).Example: 20251222191648030d7df02f5b4054d4ca8831f1369459e25

Headers

Authorization
string
required
API key for authentication (starts with pictai_)
Authorization: YOUR_API_KEY
Content-Type
string
required
Must be set to application/json
Content-Type: application/json

Request Body

The request body must contain the complete project object retrieved from the Get Project by ID endpoint. Modify only the fields you need to change while preserving all other fields.
Do not modify project fields if their usage is unclear. Incorrect modifications can cause unexpected behavior or corrupt your project. If you have questions about specific fields or their intended use, please contact our support team at [email protected] before making changes.

Updatable Video Elements

The following sections describe the video element fields that can be safely modified. These structures match the response from the Get Project by ID endpoint.

Project-Level Fields

These top-level fields can be safely updated:
{
  "projectName": "My Updated Video",
  "audioSpeed": 100,
  "videoVolume": 50
}
FieldTypeDescription
projectNamestringName of the project
audioSpeednumberAudio playback speed percentage (100 = normal)
videoVolumenumberBackground video volume level (0-100)

Scene Text (scenes[].text and scenes[].sentence)

Update the display text and narration for each scene:
{
  "scenes": [
    {
      "text": "Your new scene text here",
      "sentence": [
        {
          "text": "Your new ",
          "decoration": ["decor-bold"]
        },
        {
          "text": "scene text",
          "highlight": true,
          "decoration": ["decor-underline"]
        },
        {
          "text": " here"
        }
      ],
      "keywords": ["scene text"]
    }
  ]
}
FieldTypeDescription
textstringPlain text version of the scene narration
sentencearrayArray of text segments with formatting
sentence[].textstringText content of the segment
sentence[].highlightbooleanApply keyword highlighting
sentence[].decorationarrayText decorations: decor-bold, decor-underline
sentence[].casestringText case: none, uppercase, lowercase
keywordsarrayArray of highlighted keyword strings

Scene Text Styling (scenes[].styleData)

Modify text appearance for each scene:
{
  "scenes": [
    {
      "styleData": {
        "fontName": "Arial",
        "fontDisplayName": "Arial",
        "fontSize": "42",
        "fontColor": "rgb(255,255,255)",
        "fontWeight": 400,
        "textAlign": "left",
        "keywordColor": "rgba(141, 208, 229, 1)",
        "textBackgroundColor": "rgba(0,0,0,0.35)",
        "textShadowColor": "rgba(0,0,0,0)",
        "textShadowWidthFr": 0.03,
        "maxLines": 2,
        "width": 0.7,
        "preset": "bottom-left"
      }
    }
  ]
}
FieldTypeDescription
fontNamestringFont family name
fontSizestringFont size in pixels
fontColorstringText color (RGB format)
fontWeightnumberFont weight (400=normal, 700=bold)
textAlignstringAlignment: left, center, right
keywordColorstringHighlight color (RGBA format)
textBackgroundColorstringBackground color (RGBA format)
maxLinesnumberMaximum display lines
widthnumberContainer width (0-1)
presetstringPosition: bottom-left, bottom-center, center-center, etc.

Scene Settings (scenes[].settings)

Control scene playback behavior:
{
  "scenes": [
    {
      "settings": {
        "hideText": false
      }
    }
  ]
}
FieldTypeDescription
hideTextbooleanHide subtitle/caption text for this scene

Background Image (scenes[].background with type: "image")

Update the background image for a scene:
{
  "scenes": [
    {
      "background": {
        "type": "image",
        "elementData": {
          "url": "https://your-image-url.com/image.jpg",
          "preview_jpg": "https://your-image-url.com/preview.jpg",
          "thumb": "https://your-image-url.com/thumb.jpg",
          "thumb_jpg": "https://your-image-url.com/thumb.jpg",
          "library": "uploads",
          "libraryItemId": "your-item-id",
          "duration": 0
        },
        "styleData": {
          "kenBurns": "kb-364683-oqt0",
          "imageZoomPan": true,
          "width": 0.7,
          "aspectRatio": 1.78,
          "preset": "center-center",
          "colorOverlay": {
            "hide": false,
            "bgColor": "rgb(0,37,60)",
            "opacity": 0.5
          }
        }
      }
    }
  ]
}
FieldTypeDescription
typestringMust be "image"
elementData.urlstringFull resolution image URL
elementData.preview_jpgstringPreview image URL
elementData.thumbstringThumbnail URL
elementData.librarystringSource: uploads, unsplash, story_blocks, getty
styleData.imageZoomPanbooleanEnable Ken Burns zoom/pan effect
styleData.colorOverlayobjectColor overlay settings

Background Video (scenes[].background with type: "video")

Update the background video for a scene:
{
  "scenes": [
    {
      "background": {
        "type": "video",
        "elementData": {
          "url": "https://your-video-url.com/video.mp4",
          "preview_jpg": "https://your-video-url.com/preview.jpg",
          "thumb": "https://your-video-url.com/thumb.mp4",
          "thumb_jpg": "https://your-video-url.com/thumb.jpg",
          "library": "uploads",
          "libraryItemId": "your-item-id",
          "duration": 10,
          "description": "Video description"
        },
        "styleData": {
          "imageZoomPan": true
        },
        "settings": {
          "loopVideo": true
        }
      }
    }
  ]
}
FieldTypeDescription
typestringMust be "video"
elementData.urlstringVideo file URL
elementData.durationnumberVideo duration in seconds
elementData.librarystringSource: uploads, story_blocks, getty, pexels
settings.loopVideobooleanLoop video playback

Solid Color Background (scenes[].background with type: "solid")

Set a solid color background:
{
  "scenes": [
    {
      "background": {
        "type": "solid",
        "elementData": {
          "color": "rgb(69,123,113)"
        },
        "styleData": {}
      }
    }
  ]
}

Video Element Overlay (scenes[].elements[] with type: "video")

Update video clip overlays within a scene:
{
  "scenes": [
    {
      "elements": [
        {
          "elementId": "existing-element-id",
          "type": "video",
          "isLogo": false,
          "hide": false,
          "settings": {
            "loopVideo": true,
            "muteClipAudio": true
          },
          "elementData": {
            "url": "https://your-video-url.com/clip.mp4",
            "preview_jpg": "https://your-video-url.com/preview.jpg",
            "thumb": "https://your-video-url.com/thumb.mp4",
            "thumb_jpg": "https://your-video-url.com/thumb.jpg",
            "library": "uploads",
            "libraryItemId": "your-item-id",
            "duration": 16
          },
          "styleData": {
            "top": 4.89,
            "left": 3.96,
            "width": 0.92,
            "aspectRatio": 1.78,
            "preset": null,
            "colorOverlay": {
              "hide": false,
              "bgColor": "rgb(110,111,132)",
              "opacity": 0.3
            }
          }
        }
      ]
    }
  ]
}
FieldTypeDescription
elementIdstringUnique element identifier (preserve existing)
typestringMust be "video"
hidebooleanHide this element
settings.loopVideobooleanLoop the video clip
settings.muteClipAudiobooleanMute the video’s audio
elementData.urlstringVideo file URL
styleData.topnumberVertical position (%)
styleData.leftnumberHorizontal position (%)
styleData.widthnumberElement width (0-1)
styleData.colorOverlayobjectColor overlay settings

Text Element Overlay (scenes[].elements[] with type: "text")

Update text overlay elements within a scene:
{
  "scenes": [
    {
      "elements": [
        {
          "elementId": "existing-element-id",
          "type": "text",
          "componentName": "main_title",
          "settings": {
            "textMode": "writeAnything"
          },
          "elementData": {
            "sentence": [
              {
                "text": "Your Custom Text",
                "decoration": ["decor-bold", "decor-underline"]
              }
            ]
          },
          "styleData": {
            "fontName": "Arial",
            "fontSize": "42",
            "fontColor": "rgb(255,255,255)",
            "textAlign": "center",
            "preset": "center-center",
            "width": 0.7,
            "animation": {
              "textAnimation": [
                {
                  "name": "Typewriter",
                  "type": ["entry"],
                  "writingStyle": "character",
                  "direction": "up",
                  "speed": { "value": 1 }
                },
                {
                  "name": "None",
                  "type": ["exit"]
                }
              ],
              "textBgAnimation": []
            }
          }
        }
      ]
    }
  ]
}
FieldTypeDescription
elementIdstringUnique element identifier (preserve existing)
typestringMust be "text"
settings.textModestringuseStoryText or writeAnything
elementData.sentencearrayText segments with formatting
styleData.fontNamestringFont family
styleData.fontSizestringFont size in pixels
styleData.fontColorstringText color (RGB)
styleData.animationobjectEntry/exit animation settings

Quick Reference: Safe Updates

Field: scenes[].background (type: image)Replace background image with Ken Burns effect and color overlay.
{
  "background": {
    "type": "image",
    "elementData": {
      "url": "https://images.unsplash.com/photo-example",
      "preview_jpg": "https://images.unsplash.com/photo-example",
      "thumb": "https://images.unsplash.com/photo-example?w=200",
      "library": "unsplash",
      "libraryItemId": "mR1CIDduGLc",
      "duration": 0
    },
    "styleData": {
      "kenBurns": "kb-364683-oqt0",
      "imageZoomPan": true,
      "aspectRatio": 1.78,
      "colorOverlay": {
        "hide": false,
        "bgColor": "rgb(0,37,60)",
        "opacity": 0.5
      }
    }
  }
}
Field: scenes[].background (type: video)Replace background with a video clip.
{
  "background": {
    "type": "video",
    "elementData": {
      "url": "https://video-url.com/video.mp4",
      "preview_jpg": "https://video-url.com/preview.jpg",
      "thumb": "https://video-url.com/thumb.mp4",
      "library": "story_blocks",
      "libraryItemId": "120818",
      "duration": 10
    },
    "styleData": {
      "imageZoomPan": true
    },
    "settings": {
      "loopVideo": true
    }
  }
}
Fields: scenes[].text, scenes[].sentence, scenes[].keywordsUpdate display text, formatting, and highlighted keywords.
{
  "text": "Sweeping views with year-round sunsets",
  "sentence": [
    {
      "text": "Sweeping views",
      "highlight": true,
      "decoration": ["decor-bold", "decor-underline"]
    },
    {
      "text": " with year-round "
    },
    {
      "text": "sunsets",
      "highlight": true
    }
  ],
  "keywords": ["Sweeping views", "sunsets"]
}
Field: scenes[].styleDataUpdate text appearance, fonts, colors, and positioning.
{
  "styleData": {
    "fontName": "Arial",
    "fontDisplayName": "Arial",
    "fontSize": "42",
    "fontColor": "rgb(255,255,255)",
    "fontWeight": 400,
    "textAlign": "left",
    "keywordColor": "rgba(141, 208, 229, 1)",
    "textBackgroundColor": "rgba(0,0,0,0.35)",
    "textShadowColor": "rgba(0,0,0,0)",
    "maxLines": 2,
    "width": 0.7,
    "preset": "bottom-left"
  }
}
Field: scenes[].settingsControl text visibility for the scene.
{
  "settings": {
    "hideText": false
  }
}
Field: scenes[].elements[] (type: video)Update video clips placed as overlays within scenes.
{
  "elements": [{
    "type": "video",
    "isLogo": false,
    "hide": false,
    "elementData": {
      "url": "https://video-url.com/clip.mp4",
      "preview_jpg": "https://video-url.com/preview.jpg",
      "library": "story_blocks",
      "duration": 16
    },
    "settings": {
      "loopVideo": true,
      "muteClipAudio": true
    },
    "styleData": {
      "top": 4.89,
      "left": 3.96,
      "width": 0.92,
      "aspectRatio": 1.78,
      "colorOverlay": {
        "hide": false,
        "bgColor": "rgb(110,111,132)",
        "opacity": 0.3
      }
    }
  }]
}
Field: scenes[].elements[] (type: text)Update text overlays and their styling/animations.
{
  "elements": [{
    "type": "text",
    "componentName": "main_title",
    "settings": {
      "textMode": "writeAnything"
    },
    "elementData": {
      "sentence": [{
        "text": "A Stunning Masterpiece",
        "decoration": ["decor-underline", "decor-bold"]
      }]
    },
    "styleData": {
      "fontName": "Arial",
      "fontSize": "42",
      "fontColor": "rgb(255,255,255)",
      "textAlign": "left",
      "preset": "bottom-left",
      "animation": {
        "textAnimation": [{
          "name": "Typewriter",
          "type": ["entry"],
          "writingStyle": "character",
          "speed": { "value": 1 }
        }]
      }
    }
  }]
}
Fields: projectName, audioSpeed, videoVolumeUpdate basic project configuration.
{
  "projectName": "AI Video Creation Guide",
  "audioSpeed": 100,
  "videoVolume": 50
}

Fields to Avoid Modifying

Do Not Modify These Fields unless you fully understand their structure and dependencies:
  • sceneId, elementId, projectId - Unique identifiers
  • partitionKey, sortKey - Database keys
  • audio_id, voiceOverId, audioId - Audio reference IDs
  • assetResponseId - Asset tracking identifiers
  • schemaVersion - Project schema version
  • approximateCreationDateTime - System timestamps
  • createdBy, modifiedBy, cognito_id - User identifiers
  • audios - Audio configuration (complex dependencies)
  • word_markers, time_markers, subScenes - Audio timing data
Modifying these fields without proper understanding can cause project corruption or rendering failures. Contact [email protected] if you need guidance.

Response

The API returns a JSON response indicating the success or failure of the update operation. Success Response Fields:
FieldTypeDescription
successbooleantrue if the update was successful
messagestringConfirmation message
projectobjectThe updated project object with all current values
Error Response Fields:
FieldTypeDescription
successbooleanfalse if the update failed
messagestringError description
errorstringDetailed error information (if available)

Response Examples

{
  "success": true,
  "message": "Project updated successfully",
  "project": {
    "projectName": "Updated Project Name",
    "audioSpeed": 100,
    "videoVolume": 50,
    "scenes": [
      {
        "text": "Updated scene text",
        "sentence": [
          {
            "text": "Updated scene text",
            "highlight": true
          }
        ],
        "settings": {
          "hideText": false
        },
        "background": {
          "type": "image",
          "elementData": {
            "url": "https://new-media-url.com/image.jpg"
          }
        }
      }
    ]
  }
}

Code Examples

Replace YOUR_API_KEY with your actual API key that starts with pictai_
# First, get the current project
PROJECT_DATA=$(curl --request GET \
  --url 'https://api.pictory.ai/pictoryapis/v2/projects/YOUR_PROJECT_ID' \
  --header 'Authorization: YOUR_API_KEY' \
  --header 'accept: application/json')

# Modify the project data (using jq)
UPDATED_DATA=$(echo $PROJECT_DATA | jq '.projectName = "Updated Name"')

# Send the update
curl --request PUT \
  --url 'https://api.pictory.ai/pictoryapis/v2/projects/YOUR_PROJECT_ID' \
  --header 'Authorization: YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data "$UPDATED_DATA"

Usage Notes

Always Retrieve Before Update: Always fetch the current project state using the GET endpoint before making modifications. This ensures you have the complete object with all required fields.
Complete Object Required: Even if you only want to change one field, you must send the entire project object. Omitting fields will cause them to be removed from the project.
Render After Update: Updating a project only saves the changes to the project data. To generate a new video with your updates, you must call the Render Project endpoint after the update is complete.
Test Changes First: When making significant updates, consider testing on a copy of the project first to ensure your modifications don’t cause rendering issues.

Common Use Cases

1. Update Scene Background Visual

Replace the background media for a specific scene:
import requests

def update_scene_background(project_id, scene_index, new_media_url, media_type, api_key):
    """
    Update the background visual for a specific scene

    media_type: "image" or "video"
    """
    headers = {"Authorization": api_key, "Content-Type": "application/json"}

    # Get current project
    get_url = f"https://api.pictory.ai/pictoryapis/v2/projects/{project_id}"
    response = requests.get(get_url, headers=headers)
    project = response.json()

    # Update the scene background
    if scene_index < len(project.get('scenes', [])):
        background = project['scenes'][scene_index].get('background', {})
        background['type'] = media_type
        background['elementData'] = background.get('elementData', {})
        background['elementData']['url'] = new_media_url
        background['elementData']['preview_jpg'] = new_media_url
        background['elementData']['library'] = 'uploads'

        if media_type == 'video':
            background['settings'] = {'loopVideo': True}

        project['scenes'][scene_index]['background'] = background
        print(f"Updated scene {scene_index} background to: {new_media_url}")

        # Send update
        put_url = f"https://api.pictory.ai/pictoryapis/v2/projects/{project_id}"
        update_response = requests.put(put_url, json=project, headers=headers)
        result = update_response.json()

        if result.get('success'):
            print("Project updated successfully")
            return result
        else:
            print(f"Update failed: {result.get('message')}")
            return None
    else:
        print(f"Scene index {scene_index} out of range")
        return None

# Example usage
update_scene_background(
    "YOUR_PROJECT_ID",
    0,  # First scene
    "https://your-media-url.com/new-image.jpg",
    "image",
    "YOUR_API_KEY"
)

2. Update Scene Text

Modify the text and sentence for one or more scenes:
async function updateSceneText(projectId, sceneUpdates, apiKey) {
  const headers = {
    'Authorization': `${apiKey}`,
    'Content-Type': 'application/json'
  };

  // Get current project
  const getResponse = await fetch(
    `https://api.pictory.ai/pictoryapis/v2/projects/${projectId}`,
    { headers }
  );
  const project = await getResponse.json();

  // Update scene text
  sceneUpdates.forEach(({ sceneIndex, newText, keywords }) => {
    if (sceneIndex < project.scenes.length) {
      // Update the text field
      project.scenes[sceneIndex].text = newText;

      // Update sentence array with formatting
      project.scenes[sceneIndex].sentence = [
        {
          text: newText,
          highlight: false,
          decoration: ['decor-bold']
        }
      ];

      // Update keywords if provided
      if (keywords) {
        project.scenes[sceneIndex].keywords = keywords;
      }

      console.log(`Updated scene ${sceneIndex} text`);
    }
  });

  // Send update
  const updateResponse = await fetch(
    `https://api.pictory.ai/pictoryapis/v2/projects/${projectId}`,
    {
      method: 'PUT',
      headers,
      body: JSON.stringify(project)
    }
  );

  const result = await updateResponse.json();
  return result;
}

// Example usage
const updates = [
  { sceneIndex: 0, newText: 'A Stunning Masterpiece', keywords: ['Stunning Masterpiece'] },
  { sceneIndex: 1, newText: 'Sweeping views with year-round sunsets', keywords: ['Sweeping views', 'sunsets'] }
];

const result = await updateSceneText('YOUR_PROJECT_ID', updates, 'YOUR_API_KEY');
console.log('Update result:', result);

3. Update Scene Settings and Element Settings

Apply settings changes to scenes and their elements:
def update_scene_settings(project_id, settings_updates, api_key):
    """
    Apply settings to multiple scenes

    settings_updates: dict with scene indices as keys and settings as values
    Note:
      - scenes[].settings only supports: hideText
      - scenes[].elements[].settings supports: loopVideo, muteClipAudio
      - scenes[].background.settings supports: loopVideo (for video backgrounds)
      - scenes[].background.styleData supports: imageZoomPan

    Example: {
        0: {"hideText": True},
        2: {"hideText": False}
    }
    """
    headers = {"Authorization": api_key, "Content-Type": "application/json"}

    # Get current project
    get_url = f"https://api.pictory.ai/pictoryapis/v2/projects/{project_id}"
    response = requests.get(get_url, headers=headers)
    project = response.json()

    # Update scene settings (only hideText is supported at scene level)
    for scene_index, new_settings in settings_updates.items():
        if scene_index < len(project.get('scenes', [])):
            current_settings = project['scenes'][scene_index].get('settings', {})
            # Only update hideText at scene level
            if 'hideText' in new_settings:
                current_settings['hideText'] = new_settings['hideText']
            project['scenes'][scene_index]['settings'] = current_settings
            print(f"Updated settings for scene {scene_index}")

    # Send update
    put_url = f"https://api.pictory.ai/pictoryapis/v2/projects/{project_id}"
    update_response = requests.put(put_url, json=project, headers=headers)

    return update_response.json()


def update_element_settings(project_id, scene_index, element_index, element_settings, api_key):
    """
    Update settings for a specific video element overlay

    element_settings supports: loopVideo, muteClipAudio
    """
    headers = {"Authorization": api_key, "Content-Type": "application/json"}

    # Get current project
    get_url = f"https://api.pictory.ai/pictoryapis/v2/projects/{project_id}"
    response = requests.get(get_url, headers=headers)
    project = response.json()

    scenes = project.get('scenes', [])
    if scene_index < len(scenes):
        elements = scenes[scene_index].get('elements', [])
        if element_index < len(elements):
            current_settings = elements[element_index].get('settings', {})
            current_settings.update(element_settings)
            project['scenes'][scene_index]['elements'][element_index]['settings'] = current_settings
            print(f"Updated element {element_index} settings in scene {scene_index}")

    # Send update
    put_url = f"https://api.pictory.ai/pictoryapis/v2/projects/{project_id}"
    update_response = requests.put(put_url, json=project, headers=headers)

    return update_response.json()


# Example usage - Update scene settings (hideText only)
scene_settings = {
    0: {"hideText": True},
    2: {"hideText": False}
}
result = update_scene_settings("YOUR_PROJECT_ID", scene_settings, "YOUR_API_KEY")
print(f"Scene settings update successful: {result.get('success')}")

# Example usage - Update video element settings (loopVideo, muteClipAudio)
result = update_element_settings(
    "YOUR_PROJECT_ID",
    scene_index=0,
    element_index=0,
    element_settings={"loopVideo": True, "muteClipAudio": True},
    api_key="YOUR_API_KEY"
)
print(f"Element settings update successful: {result.get('success')}")

4. Update Project Metadata

Change project name and playback settings:
async function updateProjectMetadata(projectId, metadata, apiKey) {
  const headers = {
    'Authorization': `${apiKey}`,
    'Content-Type': 'application/json'
  };

  // Get current project
  const getResponse = await fetch(
    `https://api.pictory.ai/pictoryapis/v2/projects/${projectId}`,
    { headers }
  );
  const project = await getResponse.json();

  // Update metadata
  if (metadata.name) project.projectName = metadata.name;
  if (metadata.audioSpeed) project.audioSpeed = metadata.audioSpeed;
  if (metadata.videoVolume !== undefined) project.videoVolume = metadata.videoVolume;

  console.log('Updated project metadata:', metadata);

  // Send update
  const updateResponse = await fetch(
    `https://api.pictory.ai/pictoryapis/v2/projects/${projectId}`,
    {
      method: 'PUT',
      headers,
      body: JSON.stringify(project)
    }
  );

  return await updateResponse.json();
}

// Example usage
const metadata = {
  name: 'My Updated Project',
  audioSpeed: 105,
  videoVolume: 80
};

const result = await updateProjectMetadata('YOUR_PROJECT_ID', metadata, 'YOUR_API_KEY');
console.log('Result:', result);

5. Replace All Scene Backgrounds

Replace backgrounds for all scenes at once:
def replace_all_backgrounds(project_id, media_items, api_key):
    """
    Replace background media for all scenes

    media_items: list of dicts with 'url' and 'type' keys
    Example: [
        {"url": "https://example.com/image1.jpg", "type": "image"},
        {"url": "https://example.com/video1.mp4", "type": "video"},
    ]
    """
    headers = {"Authorization": api_key, "Content-Type": "application/json"}

    # Get current project
    get_url = f"https://api.pictory.ai/pictoryapis/v2/projects/{project_id}"
    response = requests.get(get_url, headers=headers)
    project = response.json()

    scenes = project.get('scenes', [])

    if len(media_items) != len(scenes):
        print(f"Warning: {len(media_items)} items provided for {len(scenes)} scenes")
        return None

    # Update all scene backgrounds
    for i, media in enumerate(media_items):
        background = scenes[i].get('background', {})
        background['type'] = media['type']
        background['elementData'] = background.get('elementData', {})
        background['elementData']['url'] = media['url']
        background['elementData']['preview_jpg'] = media['url']
        background['elementData']['library'] = 'uploads'

        if media['type'] == 'video':
            background['settings'] = {'loopVideo': True}
            background['elementData']['duration'] = media.get('duration', 10)

        scenes[i]['background'] = background
        print(f"Scene {i}: {media['url']} ({media['type']})")

    project['scenes'] = scenes

    # Send update
    put_url = f"https://api.pictory.ai/pictoryapis/v2/projects/{project_id}"
    update_response = requests.put(put_url, json=project, headers=headers)

    return update_response.json()

# Example usage
new_backgrounds = [
    {"url": "https://media-url.com/scene1.jpg", "type": "image"},
    {"url": "https://media-url.com/scene2.mp4", "type": "video", "duration": 15},
    {"url": "https://media-url.com/scene3.jpg", "type": "image"}
]

result = replace_all_backgrounds("YOUR_PROJECT_ID", new_backgrounds, "YOUR_API_KEY")
if result and result.get('success'):
    print("All backgrounds updated successfully")

6. Safe Update with Validation

Implement validation before updating:
import copy

def safe_update_project(project_id, update_function, api_key):
    """
    Safely update project with validation

    update_function: function that takes project dict and modifies it
    """
    headers = {"Authorization": api_key, "Content-Type": "application/json"}

    # Get current project
    get_url = f"https://api.pictory.ai/pictoryapis/v2/projects/{project_id}"
    response = requests.get(get_url, headers=headers)

    if response.status_code != 200:
        print("Failed to fetch project")
        return None

    original_project = response.json()
    updated_project = copy.deepcopy(original_project)

    # Apply updates
    try:
        update_function(updated_project)
    except Exception as e:
        print(f"Error applying updates: {e}")
        return None

    # Validate critical fields are present
    required_fields = ['projectName', 'scenes', 'schemaVersion']
    for field in required_fields:
        if field not in updated_project:
            print(f"Critical field '{field}' missing after update")
            return None

    # Send update
    put_url = f"https://api.pictory.ai/pictoryapis/v2/projects/{project_id}"
    update_response = requests.put(put_url, json=updated_project, headers=headers)

    result = update_response.json()

    if result.get('success'):
        print("Project updated successfully")
    else:
        print(f"Update failed: {result.get('message')}")

    return result

# Example usage
def my_updates(project):
    """Define your updates here"""
    project['projectName'] = 'New Name'
    project['audioSpeed'] = 95

    # Hide text for first scene (scenes[].settings.hideText)
    if project['scenes']:
        if 'settings' not in project['scenes'][0]:
            project['scenes'][0]['settings'] = {}
        project['scenes'][0]['settings']['hideText'] = True

    # Mute audio for first video element (elements[].settings.muteClipAudio)
    if project['scenes'] and project['scenes'][0].get('elements'):
        element = project['scenes'][0]['elements'][0]
        if element.get('type') == 'video':
            if 'settings' not in element:
                element['settings'] = {}
            element['settings']['muteClipAudio'] = True

result = safe_update_project("YOUR_PROJECT_ID", my_updates, "YOUR_API_KEY")

Best Practices

Safety Guidelines

  1. Always Fetch First: Get the current project state before making any modifications
  2. Preserve All Fields: Include all fields in the update request, even if unchanged
  3. Test on Copies: Test significant changes on duplicate projects first
  4. Validate Before Sending: Ensure all required fields are present before updating
  5. Keep Backups: Save the original project state before applying updates

Common Pitfalls to Avoid

  • ❌ Partial Updates: Sending only modified fields will delete other fields
  • ❌ Missing Required Fields: Omitting critical fields causes project corruption
  • ❌ Invalid Values: Using incorrect data types or formats for fields
  • ❌ Modifying System Fields: Changing internal IDs or metadata
  • ❌ No Validation: Updating without checking the project state first

Performance Tips

  • Batch multiple changes in a single update request
  • Minimize the frequency of updates during active editing
  • Cache the project object locally during editing sessions
  • Only fetch/update when necessary to reduce API calls