Brightcove provides an API that allows developers to programmatically upload videos to their platform, enabling seamless integration into workflows for video management. By using Brightcove's API, you can upload videos in various formats, manage video metadata, and automate content distribution processes.
Prerequisites for Uploading Videos to Brightcove
Before you start uploading videos to Brightcove using their API, ensure you have the following:
- Brightcove Account: You must have a Brightcove account to access the API and obtain the necessary credentials.
- API Credentials: You will need an API key and an access token to authenticate requests. These can be generated from your Brightcove account settings.
- Video File: The video file must be in a format supported by Brightcove (e.g., MP4, MOV, etc.).
- API Libraries: Brightcove provides SDKs for various programming languages, including Python, JavaScript, and Ruby. You can also make direct HTTP requests if you prefer not to use the SDK.
Set Up Authentication with Brightcove API
To interact with Brightcove's video management services, you'll need to authenticate using OAuth or the Brightcove API credentials (Client ID and Client Secret). This process grants you access to upload and manage videos on your account.
Generate API Credentials
Step 1: Log in to your Brightcove account.
Step 2: Navigate to Account Settings and then to API.
Step 3: Create a new API application to obtain a Client ID and Client Secret.
OAuth Authentication
To authenticate your requests, you need to obtain an access token by using OAuth authentication. Below is an example using Node.js to get an access token:
const axios = require('axios');
const qs = require('qs');
const client_id = 'your-client-id';
const client_secret = 'your-client-secret';
const authUrl = 'https://oauth.brightcove.com/v4/access_token';
axios.post(authUrl, qs.stringify({
client_id: client_id,
client_secret: client_secret,
grant_type: 'client_credentials'
}), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(response => {
const accessToken = response.data.access_token;
console.log('Access Token:', accessToken);
})
.catch(error => {
console.error('Error obtaining access token:', error.response.data);
});Explanation:
- axios.post: Sends a POST request to obtain the access token.
- access_token: Required for subsequent requests.
- grant_type:'client_credentials': Specifies the type of OAuth flow.
Upload Video to Brightcove Using API
Once authenticated, you can upload a video using the Media API. Brightcove provides a multi-step process for video uploads: First, you create an upload URL, then you upload the video, and finally, you publish it.
Create Upload URL
To upload a video to Brightcove, first create an upload URL. This ensures the video is ready for uploading and will be available in the Brightcove Media Library once the upload is complete.
const axios = require('axios');
const accessToken = 'your-access-token';
const accountId = 'your-account-id';
const createVideoUrl = `https://cms.api.brightcove.com/v1/accounts/${accountId}/videos`;
axios.post(createVideoUrl, {
name: 'Customer Support Demo Video',
description: 'Uploaded via API'
}, {
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
}
})
.then(response => {
const videoId = response.data.id;
console.log('Created video with ID:', videoId);
})
.catch(error => {
console.error('Error creating video object:', error.response.data);
});Explanation:
- POST: Creates the video entry in Brightcove's system.
- description: Optional text describing the video.
- Authorization: Bearer token for authentication
Upload Video File
Now that we have the upload URL, next we will upload the video. Here"s an example using the FormData API and axios to upload the video:
const axios = require('axios');
const accessToken = 'your-access-token';
const accountId = 'your-account-id';
const videoId = 'your-video-id';
const publicVideoUrl = 'https://your-public-url/video.mp4';
const ingestUrl = `https://ingest.api.brightcove.com/v1/accounts/${accountId}/videos/${videoId}/ingest-requests`;
axios.post(ingestUrl, {
master: { url: publicVideoUrl }
}, {
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
}
})
.then(response => {
console.log('Ingest request submitted:', response.data);
})
.catch(error => {
console.error('Error submitting ingest request:', error.response.data);
});Explanation:
- master: { url: publicVideoUrl }: Specifies the URL of the video file to be uploaded.
- axios.post: Sends the video to Brightcove for processing.
Complete Upload Process
Once the video is uploaded, Brightcove will process the video and make it available in your Media Library. You can now use the complete upload API to finalize the process:
const axios = require('axios');
const accessToken = 'your-access-token';
const accountId = 'your-account-id';
const videoId = 'your-video-id';
const statusUrl = `https://cms.api.brightcove.com/v1/accounts/${accountId}/videos/${videoId}`;
axios.get(statusUrl, {
headers: {
'Authorization': `Bearer ${accessToken}`
}
})
.then(response => {
console.log('Video status:', response.data);
})
.catch(error => {
console.error('Error checking video status:', error.response.data);
});Explanation:
- GET: Fetches the current status of the video.
- Authorization: Required for access.
Handling Upload Errors and Retries
During the upload process, various errors may occur (e.g., network failures or timeouts). It"s essential to handle errors gracefully and implement retries to ensure the video is uploaded successfully.
Example: Retry Logic
const retryIngest = (url, data, headers, retries = 3) => {
return axios.post(url, data, { headers })
.catch(error => {
if (retries > 0) {
console.log('Retrying ingest request...');
return retryIngest(url, data, headers, retries - 1);
} else {
console.error('Ingest failed after multiple retries:', error.response.data);
}
});
};
// Usage example:
retryIngest(ingestUrl, { master: { url: publicVideoUrl } }, {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
});Explanation:
- retryIngest: A function to retry the ingest request in case of failure.
- retries: The number of retry attempts before failing.
- axios.post: Sends the request to Brightcove.

