{ "success": false, "message": "Template not found"}
{ "code": "INVALID_REQUEST", "message": "Invalid scene structure"}
Overview
Update the scene structure and content of an existing video template. This endpoint allows you to modify the template’s scene array, which defines the video’s structure, content, and visual elements.
Template Modification: Updating a template affects all future videos created from it. Existing videos created from this template will not be affected.
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/v1/templates/{templateId}
Request Parameters
Path Parameters
string
required
The unique identifier of the template to updateExample: 202512230204424435786014d42904bbc95813430789fe736
Headers
string
required
API key for authentication (starts with pictai_)
Authorization: YOUR_API_KEY
Body Parameters
array of objects
required
Array of scene objects that define the template structure. Each scene represents a segment in the video template with its own content, visuals, and timing.
Show scene object structure
The exact structure of scene objects should match the scene format used in Pictory projects. Common fields include:
Test Before Production: Always test template updates with non-production templates first to ensure the scene structure is valid and produces the expected results.
Scene Structure: The scenes array should match the structure used in Pictory projects. Refer to the Update Project endpoint documentation for scene object examples.
Version Control: Consider keeping backup copies of template configurations before making updates, especially for templates actively used in production.
Common Use Cases
1. Update Template Text Content
Modify the text content across all scenes in a template:
import requestsdef validate_scenes(scenes): """ Validate scene structure before updating """ if not isinstance(scenes, list): return False, "Scenes must be an array" if len(scenes) == 0: return False, "Scenes array cannot be empty" for i, scene in enumerate(scenes): if not isinstance(scene, dict): return False, f"Scene {i} must be an object" # Add more validation as needed if 'text' in scene and not isinstance(scene['text'], str): return False, f"Scene {i} text must be a string" if 'duration' in scene and not isinstance(scene['duration'], (int, float)): return False, f"Scene {i} duration must be a number" return True, "Validation passed"def safe_update_template(template_id, scenes, api_key): """ Update template with validation """ # Validate scenes is_valid, message = validate_scenes(scenes) if not is_valid: print(f"Validation error: {message}") return False # Update template url = f"https://api.pictory.ai/pictoryapis/v1/templates/{template_id}" headers = { "Authorization": api_key, "Content-Type": "application/json" } try: response = requests.put( url, headers=headers, json={"scenes": scenes} ) result = response.json() if result.get('success'): print("Template updated successfully") return True else: print(f"Update failed: {result.get('message')}") return False except Exception as e: print(f"Error: {e}") return False# Example usagescenes = [ {"text": "Validated scene 1", "duration": 5}, {"text": "Validated scene 2", "duration": 8}]safe_update_template("YOUR_TEMPLATE_ID", scenes, "YOUR_API_KEY")
5. Rollback Template Changes
Implement a rollback mechanism for template updates:
class TemplateManager { constructor(apiKey) { this.apiKey = apiKey; this.backups = new Map(); } async backupTemplate(templateId, scenes) { // Store backup locally this.backups.set(templateId, { scenes: JSON.parse(JSON.stringify(scenes)), timestamp: new Date().toISOString() }); console.log(`Backup created for template ${templateId}`); } async updateTemplate(templateId, newScenes) { const url = `https://api.pictory.ai/pictoryapis/v1/templates/${templateId}`; try { const response = await fetch(url, { method: 'PUT', headers: { 'Authorization': this.apiKey, 'Content-Type': 'application/json' }, body: JSON.stringify({ scenes: newScenes }) }); const result = await response.json(); if (result.success) { console.log('Template updated successfully'); return { success: true, result }; } else { console.error('Update failed:', result.message); return { success: false, error: result.message }; } } catch (error) { console.error('Error updating template:', error); return { success: false, error: error.message }; } } async rollbackTemplate(templateId) { const backup = this.backups.get(templateId); if (!backup) { console.error('No backup found for this template'); return false; } console.log(`Rolling back to backup from ${backup.timestamp}`); return await this.updateTemplate(templateId, backup.scenes); }}// Example usageconst manager = new TemplateManager('YOUR_API_KEY');// Backup current stateconst currentScenes = [/* current scenes */];await manager.backupTemplate('YOUR_TEMPLATE_ID', currentScenes);// Update templateconst newScenes = [/* new scenes */];const result = await manager.updateTemplate('YOUR_TEMPLATE_ID', newScenes);// Rollback if neededif (!result.success) { await manager.rollbackTemplate('YOUR_TEMPLATE_ID');}
Best Practices
Safety Guidelines
Backup First: Always backup the current template configuration before making updates
Validate Structure: Validate scene structure before sending updates to prevent errors
Test Changes: Test template updates in a development environment first
Version Control: Maintain version history of template configurations
Gradual Rollout: When updating production templates, do so gradually and monitor results
Common Pitfalls
❌ No Backup: Updating without backing up the current configuration
❌ Invalid Structure: Sending incorrectly structured scene objects
❌ Missing Fields: Omitting required fields in scene objects
❌ Production Testing: Testing changes directly on production templates
Performance Tips
Batch similar updates to reduce API calls
Cache template configurations locally to avoid repeated fetches
Use validation before updates to prevent failed requests