Text to Video with Vimeo Integration
This example demonstrates how to create a video and automatically upload it to Vimeo. The video will be uploaded to your connected Vimeo account with custom privacy settings and folder organization.
Overview
This example covers:
- Getting an access token
- Creating a video with Vimeo destination
- Configuring Vimeo privacy settings
- Organizing videos in Vimeo folders
- Understanding Vimeo connection requirements
- Monitoring job status and retrieving both video URL and Vimeo URL
Node.js Example
Prerequisites
npm install axiosComplete Code
import axios from "axios";
const API_BASE_URL = "https://api.pictory.ai/pictoryapis";
const CLIENT_ID = "YOUR_CLIENT_ID";
const CLIENT_SECRET = "YOUR_CLIENT_SECRET";
const STORY_TEXT =
"AI is poised to significantly impact educators and course creators on social media. By automating tasks like content generation, visual design, and video editing, AI will save time and enhance consistency.";
async function createTextToVideoWithVimeo() {
try {
// Step 1: Get Access Token
console.log("Step 1: Getting access token...");
const tokenResponse = await axios.post(
`${API_BASE_URL}/v1/oauth2/token`,
{
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
},
{
headers: {
"Content-Type": "application/json",
},
}
);
const accessToken = tokenResponse.data.access_token;
console.log("Access token obtained successfully");
console.log("Token expires in:", tokenResponse.data.expires_in, "seconds\n");
// Step 2: Create Video with Vimeo Integration
console.log("Step 2: Creating video with Vimeo destination...");
const storyboardResponse = await axios.post(
`${API_BASE_URL}/v2/video/storyboard/render`,
{
videoName: "text_to_video_vimeo",
vimeoConnectionId: "{YOUR_VIMEO_CONNECTION_ID}",
destinations: [
{
type: "vimeo",
folder_uri: "/videos/123456", // Optional: Vimeo folder URI
content_rating: ["safe"], // Optional: Content rating
privacy: {
view: "unlisted", // Options: anybody, contacts, disable, nobody, password, unlisted, users
embed: "public", // Options: private, public, whitelist
comments: "anybody", // Options: anybody, contacts, nobody
download: false, // Allow/disallow downloads
add: false, // Allow/disallow adding to albums
},
},
],
scenes: [
{
story: STORY_TEXT,
createSceneOnNewLine: false,
createSceneOnEndOfSentence: false,
},
],
},
{
headers: {
"Content-Type": "application/json",
Authorization: accessToken,
},
}
);
const renderJobId = storyboardResponse.data.data.jobId;
console.log("Video with Vimeo destination render job created");
console.log("Job ID:", renderJobId, "\n");
// Step 3: Monitor Job Status
console.log("Step 3: Monitoring job status...");
let jobCompleted = false;
let jobResult = null;
while (!jobCompleted) {
const jobStatusResponse = await axios.get(`${API_BASE_URL}/v1/jobs/${renderJobId}`, {
headers: {
Authorization: accessToken,
},
});
const status = jobStatusResponse.data.data.status;
console.log("Current status:", status);
if (status === "completed") {
jobCompleted = true;
jobResult = jobStatusResponse.data;
console.log("\nVideo created and uploaded to Vimeo successfully!");
console.log("Video URL:", jobResult.data.videoUrl);
console.log("Vimeo URL:", jobResult.data.vimeoUrl || "Processing...");
} else if (status === "failed") {
throw new Error("Job failed: " + JSON.stringify(jobStatusResponse.data));
} else {
// Wait 5 seconds before checking again
await new Promise(resolve => setTimeout(resolve, 5000));
}
}
return jobResult;
} catch (error) {
console.error("Error:", error.response?.data || error.message);
throw error;
}
}
// Run the function
createTextToVideoWithVimeo();Python Example
Prerequisites
pip install requestsComplete Code
import requests
import time
import json
API_BASE_URL = 'https://api.pictory.ai/pictoryapis'
CLIENT_ID = 'YOUR_CLIENT_ID'
CLIENT_SECRET = 'YOUR_CLIENT_SECRET'
STORY_TEXT = "AI is poised to significantly impact educators and course creators on social media. By automating tasks like content generation, visual design, and video editing, AI will save time and enhance consistency."
def create_text_to_video_with_vimeo():
try:
# Step 1: Get Access Token
print('Step 1: Getting access token...')
token_response = requests.post(
f'{API_BASE_URL}/v1/oauth2/token',
json={
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET
},
headers={
'Content-Type': 'application/json'
}
)
token_response.raise_for_status()
access_token = token_response.json()['access_token']
print('Access token obtained successfully')
print(f"Token expires in: {token_response.json()['expires_in']} seconds\n")
# Step 2: Create Video with Vimeo Integration
print('Step 2: Creating video with Vimeo destination...')
storyboard_response = requests.post(
f'{API_BASE_URL}/v2/video/storyboard/render',
json={
'videoName': 'text_to_video_vimeo',
'vimeoConnectionId': '{YOUR_VIMEO_CONNECTION_ID}',
'destinations': [
{
'type': 'vimeo',
'folder_uri': '/videos/123456', # Optional: Vimeo folder URI
'content_rating': ['safe'], # Optional: Content rating
'privacy': {
'view': 'unlisted', # Options: anybody, contacts, disable, nobody, password, unlisted, users
'embed': 'public', # Options: private, public, whitelist
'comments': 'anybody', # Options: anybody, contacts, nobody
'download': False, # Allow/disallow downloads
'add': False # Allow/disallow adding to albums
}
}
],
'scenes': [
{
'story': STORY_TEXT,
'createSceneOnNewLine': False,
'createSceneOnEndOfSentence': False
}
]
},
headers={
'Content-Type': 'application/json',
'Authorization': access_token
}
)
storyboard_response.raise_for_status()
render_job_id = storyboard_response.json()['data']['jobId']
print('Video with Vimeo destination render job created')
print(f'Job ID: {render_job_id}\n')
# Step 3: Monitor Job Status
print('Step 3: Monitoring job status...')
job_completed = False
job_result = None
while not job_completed:
job_status_response = requests.get(
f'{API_BASE_URL}/v1/jobs/{render_job_id}',
headers={
'Authorization': access_token
}
)
job_status_response.raise_for_status()
status = job_status_response.json()['data']['status']
print(f'Current status: {status}')
if status == 'completed':
job_completed = True
job_result = job_status_response.json()
print('\nVideo created and uploaded to Vimeo successfully!')
print(f"Video URL: {job_result['data']['videoUrl']}")
print(f"Vimeo URL: {job_result['data'].get('vimeoUrl', 'Processing...')}")
elif status == 'failed':
raise Exception(f"Job failed: {json.dumps(job_status_response.json())}")
else:
# Wait 5 seconds before checking again
time.sleep(5)
return job_result
except requests.exceptions.RequestException as error:
print(f'Error: {error}')
if hasattr(error, 'response') and error.response is not None:
print(f'Response: {error.response.text}')
raise
# Run the function
if __name__ == '__main__':
create_text_to_video_with_vimeo()Key Parameters
Vimeo Connection
- vimeoConnectionId: Your Vimeo connection ID (must be set up in your Pictory account first)
Destinations Array
- type: Must be
"vimeo"for Vimeo uploads - folder_uri (optional): Vimeo folder URI where the video should be uploaded (e.g.,
/videos/123456) - content_rating (optional): Array of content ratings
- Options:
"violence","drugs","language","nudity","advertisement","safe","unrated"
- Options:
Privacy Settings
-
view: Who can view the video
"anybody"- Public, anyone can view"contacts"- Only contacts can view"disable"- Video is disabled"nobody"- Private, only you can view"password"- Password protected"unlisted"- Anyone with the link can view"users"- Only specified users can view
-
embed: Embed privacy settings
"private"- Cannot be embedded"public"- Can be embedded anywhere"whitelist"- Can be embedded only on whitelisted domains
-
comments: Who can comment
"anybody"- Anyone can comment"contacts"- Only contacts can comment"nobody"- Comments disabled
-
download: Boolean - Allow/disallow video downloads
-
add: Boolean - Allow/disallow adding to albums/channels
Setting Up Vimeo Connection
Before using this API, you need to connect your Vimeo account:
- Create Vimeo Connection as explained in the API https://docs.pictory.ai/reference/createvimeoconnection
- Note the Vimeo Connection ID for API use
Use Cases
- Automatically upload marketing videos to Vimeo
- Organize videos in specific Vimeo folders
- Set appropriate privacy settings for different video types
- Streamline video distribution workflow
- Maintain video library across platforms
Multiple Destinations
You can specify multiple destinations (up to 5):
destinations: [
{
type: "vimeo",
privacy: { view: "unlisted" },
},
];Response
The API returns a job ID for monitoring the video creation progress. Once completed, you'll receive:
- The standard video URL from Pictory
- The Vimeo URL where the video was uploaded
- Any other destination URLs if multiple destinations were specified
Notes
- Replace
YOUR_CLIENT_IDandYOUR_CLIENT_SECRETwith your actual API credentials - Replace
{YOUR_VIMEO_CONNECTION_ID}with your actual Vimeo connection ID - The Vimeo connection must be active and authorized
- Vimeo upload happens asynchronously after video creation
- The
folder_urimust be a valid folder in your Vimeo account - You can specify up to 5 destinations per video
Updated about 15 hours ago
