### Install api.video client
Source: https://docs.api.video/delivery/quickstart
Install the api.video client library for Node.js.
```javascript
const ApiVideoClient = require('@api.video/nodejs-client')
```
--------------------------------
### Frontend serverUrl configuration
Source: https://docs.api.video/vod/get-started-in-5-minutes
Example of configuring the serverUrl in the frontend code.
```typescript
// src/pages/index.tsx
export default function Home() {
const serverUrl = 'http://localhost:{port}';
```
--------------------------------
### Installing Dependencies
Source: https://docs.api.video/vod/get-started-in-5-minutes
NPM commands to install necessary dependencies for the server, including express, api.video client, cors, multer, and body-parser.
```bash
//express server
$ npm install express --save
// the api.video client library
$ npm install @api.video/nodejs-client --save
// cors needed to make cross domain requests
$ npm install cors --save
// multer will read the file buffer from the request
$ npm install multer --save
// the body-preser function is to parse the incoming form request body
$ npm install body-parser --save
```
--------------------------------
### Install React Player SDK
Source: https://docs.api.video/delivery/quickstart
Command to install the api.video React Player SDK.
```bash
$ npm install --save @api.video/react-player
```
--------------------------------
### Setting up the Express Server
Source: https://docs.api.video/vod/get-started-in-5-minutes
Basic Express.js server setup to listen on port 5500 and handle POST requests.
```javascript
const express = require('express')
const app = express()
const port = 5500
app.post('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
```
--------------------------------
### Run the development server
Source: https://docs.api.video/vod/get-started-in-5-minutes
Start the Next.js development server.
```bash
$ npm run dev
```
--------------------------------
### Uploading a video endpoint
Source: https://docs.api.video/vod/get-started-in-5-minutes
Example of the frontend making a POST request to the '/upload' endpoint.
```typescript
// Uploading videos - src/pages/index.tsx
axios.post(`${serverUrl}/upload`, data).then( async res => {
```
--------------------------------
### List all videos endpoint
Source: https://docs.api.video/vod/get-started-in-5-minutes
Example of the frontend making a POST request to the '/videos' endpoint to list all videos in the workspace.
```typescript
// Listing Videos - src/pages/index.tsx
const ListVideoPage = (page: number) => {
axios.post(`${serverUrl}/videos`, {page: page}).then(res => {
```
--------------------------------
### Endpoint mapping examples
Source: https://docs.api.video/analytics/migration
Examples of how to map previous Analytics endpoints to the new ones.
```bash
/data/metrics/play/count
```
```bash
/data/buckets/play/country
```
```bash
/data/timeseries/play
```
--------------------------------
### Start method example
Source: https://docs.api.video/sdks/vod/apivideo-typescript-media-recorder
Example of using the start() method with and without the timeslice option.
```javascript
// ... mediaRecorder instantiation
mediaRecorder.start();
// or, with a 2 seconds timeslice:
// mediaRecorder.start({ timeslice: 2000 });
```
--------------------------------
### Navigate to the cloned directory
Source: https://docs.api.video/vod/get-started-in-5-minutes
Change the current directory to the cloned repository.
```bash
$ cd get-started-video-uploader
```
--------------------------------
### Initializing the api.video Client
Source: https://docs.api.video/vod/get-started-in-5-minutes
Initializes the api.video client with an API key.
```javascript
const apivideoClient = new ApiVideoClient({ apiKey: "replace with your api key" });
```
--------------------------------
### Changing the default port
Source: https://docs.api.video/vod/get-started-in-5-minutes
Modify the 'package.json' to change the default port for development and start scripts.
```json
"scripts": {
"dev": "next -p 3002",
"build": "next build",
"start": "next start -p 3002"
}
```
--------------------------------
### Clone the front-end repo
Source: https://docs.api.video/vod/get-started-in-5-minutes
Clone the Next.js frontend repository from GitHub.
```bash
$ git clone https://github.com/apivideo/get-started-video-uploader.git
```
--------------------------------
### Running the server
Source: https://docs.api.video/vod/get-started-in-5-minutes
This command shows how to run the Node.js server using the 'node' command.
```bash
node index.js
```
--------------------------------
### Adding the api.video Client Library
Source: https://docs.api.video/vod/get-started-in-5-minutes
Includes the api.video client library in the server code.
```javascript
const express = require('express');
const ApiVideoClient = require('@api.video/nodejs-client')
const app = express()
const port = 5500
```
--------------------------------
### Java API Client Example
Source: https://docs.api.video/sdks/api-clients/apivideo-java-client
Please follow the installation instruction and execute the following Java code:
```java
import video.api.client.ApiVideoClient;
import video.api.client.api.ApiException;
import video.api.client.api.models.*;
public class Example {
public static void main(String[] args) {
ApiVideoClient apiVideoClient = new ApiVideoClient("YOUR_API_KEY");
// if you rather like to use the sandbox environment:
// ApiVideoClient apiVideoClient = new ApiVideoClient("YOU_SANDBOX_API_KEY", Environment.SANDBOX);
File myVideoFile = new File("my-video.mp4");
try {
Video video = apiVideoClient.videos().create(new VideoCreationPayload().title("my video"));
video = apiVideoClient.videos().upload(video.getVideoId(), myVideoFile);
System.out.println(video);
} catch (ApiException e) {
System.err.println("Exception when calling AccountApi#get");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getMessage());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
```
--------------------------------
### Example App Setup URL
Source: https://docs.api.video/sdks/livestream/apivideo-flutter-livestream
URL to clone the example app from version control.
```git
git@github.com:apivideo/api.video-flutter-live-stream.git
```
--------------------------------
### Get hosting usage response example
Source: https://docs.api.video/reference/admin-api/Usage
Example of a successful response when retrieving hosting usage for a project.
```json
{
"items": [
{
"collected_on": "2024-08-09",
"video_duration_minutes": 235
},
{
"collected_on": "2024-08-10",
"video_duration_minutes": 454
}
]
}
```
--------------------------------
### Creating a new player theme
Source: https://docs.api.video/delivery/quickstart
Create a new player theme with custom controls color.
```javascript
const playerThemeCreationPayload = {
link: "rgba(128, 0, 128, 1)", // RGBA color for all controls. Default: rgba(255,
};
const playerTheme = await client.playerThemes.create(playerThemeCreationPayload);
```
--------------------------------
### Uploading a Video
Source: https://docs.api.video/vod/get-started-in-5-minutes
Uploads the video file to api.video after creating the video object and returns the videoId.
```javascript
// create a video object first
const video = await apivideoClient.videos.create(videoCreationPayload);
// upload the video
const uploadVideoRes = await apivideoClient.videos.upload(video.videoId, file.path)
// Add the response to the frontend request
res.json(uploadVideoRes.videoId);
```
--------------------------------
### Create Project Directory and Files
Source: https://docs.api.video/vod/get-started-in-5-minutes
Commands to create a new project directory and initialize a Node.js project.
```bash
$ mkdir apivideo-node-server
$ cd apivideo-node-server
$ npm init
$ touch index.js
```
--------------------------------
### Add the video component in React
Source: https://docs.api.video/delivery/quickstart
Example of how to add the api.video player component in a React application.
```javascript
import ApiVideoPlayer from '@api.video/react-player'
// your code
```
--------------------------------
### Request Embedded Video Asset
Source: https://docs.api.video/delivery/private-video-get-started
Example of requesting an embedded video asset using the session token.
```http
GET https://embed.api.video/vod/{video id}?token={private token}&avh={session token}
```
--------------------------------
### Request Private Video MP4 Asset
Source: https://docs.api.video/delivery/private-video-get-started
Example of requesting a private video MP4 asset using the session token.
```http
GET https://vod.api.video/vod/{video id}/token/{private token}/mp4/source.mp4?avh={session token}
```
--------------------------------
### Request Private Video Thumbnail Asset
Source: https://docs.api.video/delivery/private-video-get-started
Example of requesting a private video thumbnail asset using the session token.
```http
GET https://vod.api.video/vod/{video id}/token/{private token}/thumbnail.jpg?avh={session token}
```
--------------------------------
### Check upload status endpoint
Source: https://docs.api.video/vod/get-started-in-5-minutes
Example of the frontend making a POST request to the '/uploadStatus' endpoint to check video upload status.
```typescript
// Getting video status - src/pages/index.tsx
const checkUploadStatus = async (videoId: string) => {
return axios.post(`${serverUrl}/uploadStatus`, {videoId: videoId}).then( res => {
```
--------------------------------
### Installing the api.video client
Source: https://docs.api.video/live-streaming/add-or-delete-a-live-stream-thumbnail
To install your selected client, do the following:
```Go
go get github.com/apivideo/api.video-go-client
```
--------------------------------
### Private video example
Source: https://docs.api.video/delivery/private-video-get-started
This snippet shows how to extract private video information and generate session tokens and HTML tags for private videos.
```javascript
{
"mp4": "https://vod.api.video/vod/AABBCC/token/c77d7bf3-4e2f-4a85-9e15-5c35992c11fc/mp4/source.mp4"
}
},
]
}
```
```
--------------------------------
### Install Pods for iOS Example
Source: https://docs.api.video/sdks/livestream/react-native-livestream-component
Navigates to the iOS example directory and installs CocoaPods dependencies.
```bash
cd /example/ios && pod install
```
--------------------------------
### Creating a Video Object
Source: https://docs.api.video/vod/get-started-in-5-minutes
Handles the POST request to the /upload endpoint, creates a video object with title and description using the api.video client.
```javascript
app.post('/upload', upload.single('file'), async (req, res, next) => {
// Grab the file from the request
const file = req.file;
try {
// the video title and description
const videoCreationPayload = {
title: "My Video Test in Node",
Description: "Something I wanted to share",
}
// create a video object first
const video = await apivideoClient.videos.create(videoCreationPayload);
} catch (error) {
console.log(error)
}
if (!file) {
const error = new Error('No File')
error.httpStatusCode = 400
return next(error)
}
```
--------------------------------
### Install Dependencies and Launch Android Example
Source: https://docs.api.video/sdks/livestream/react-native-livestream-component
Installs project dependencies using yarn and launches the Android example application.
```bash
yarn && yarn example android
```
--------------------------------
### Create a project with Admin API
Source: https://docs.api.video/reference/admin-api-overview
This example demonstrates the workflow for creating a project and an associated API key using the Admin API.
```bash
curl --request POST \
--url https://admin.api.video/projects \
--header 'Accept: application/json' \
--header 'Authorization: Basic {$adminApiKey}' \
--header 'Content-Type: application/json' \
--data '
{
"name": "My Programmatically Created Project",
"region": "eu-central-1"
}
'
```
```json
{
"project_id": "{Your new project's ID}",
"created_at": "2024-08-10T17:32:28Z",
"name": "My Programmatically Created Project",
"region": "eu-central-1"
}
```
```bash
curl --request POST \
--url https://admin.api.video/projects/{Your new project's ID}/api-keys \
--header 'Accept: application/json' \
--header 'Authorization: Basic {$adminApiKey}' \
--header 'Content-Type: application/json' \
--data '
{
"name": "My API key"
}
'
```
```json
{
"project_id": "{Your new project's ID}",
"api_key_id": "{Your new API key's ID}",
"created_at": "2024-08-10T18:32:28Z",
"name": "My API key",
"value": "{The value of your actual API key}"
}
```
--------------------------------
### Get Video Response Example
Source: https://docs.api.video/reference/api/Videos
Example of a successful JSON response when retrieving video details.
```json
{
"videoId": "vi4blUQJFrYWbaG44NChkH27",
"playerId": "pl45KFKdlddgk654dspkze",
"title": "Maths video",
"description": "An amazing video explaining string theory",
"public": false,
"panoramic": false,
"mp4Support": true,
"tags": [
"maths",
"string theory",
"video"
],
"metadata": [
{
"key": "Author",
"value": "John Doe"
},
{
"key": "Format",
"value": "Tutorial"
}
],
"publishedAt": "2024-07-14T23:36:07+00:00",
"discarded": false,
"discardedAt": null,
"deletesAt": null,
"source": {
"uri": "/videos/vi4blUQJFrYWbaG44NChkH27/source"
},
"assets": {
"iframe": "",
"player": "https://embed.api.video/vod/vi4blUQJFrYWbaG44NChkH27",
"hls": "https://cdn.api.video/vod/vi4blUQJFrYWbaG44NChkH27/hls/manifest.m3u8",
"thumbnail": "https://cdn.api.video/vod/vi4blUQJFrYWbaG44NChkH27/thumbnail.jpg",
"mp4": "https://cdn.api.video/vod/vi4blUQJFrYWbaG44NChkH27/mp4/source.mp4"
}
}
```
--------------------------------
### Full example
Source: https://docs.api.video/sdks/player/apivideo-player-sdk
This example demonstrates how to create a player instance, control playback using buttons, and listen to player events like 'play' and 'pause'.
```html
...
```
--------------------------------
### Get summary details response example
Source: https://docs.api.video/reference/api/Summaries
Example JSON response for a successful retrieval of summary details.
```json
{
"abstract": "In this lecture, we discuss how complicated quantum theory is, using the famous example of Schrödingers cat. We also discuss practical applications like quantum computing.",
"takeaways": [
"Quantum theory is complicated.",
"Schrödinger's cat is neither dead, nor alive.",
"Quantum computers are super cool."
]
}
```
--------------------------------
### Get project count response example
Source: https://docs.api.video/reference/admin-api/Projects
Example of a successful response when retrieving the total number of projects.
```json
{
"count": 37
}
```
--------------------------------
### Install Dependencies
Source: https://docs.api.video/sdks/api-clients/apivideo-csharp-client
We recommend using NuGet to obtain the packages.
```csharp
Install-Package RestSharp
Install-Package Newtonsoft.Json
Install-Package JsonSubTypes
```
--------------------------------
### Get delivery usage response example
Source: https://docs.api.video/reference/admin-api/Usage
Example of a successful response when retrieving delivery usage for a project.
```json
{
"items": [
{
"collected_on": "2024-08-09",
"video_hls_duration_minutes": 10,
"video_mp4_duration_minutes": 22,
"live_stream_hls_duration_minutes": 422
},
{
"collected_on": "2024-08-10",
"video_hls_duration_minutes": 33,
"video_mp4_duration_minutes": 245,
"live_stream_hls_duration_minutes": 32
}
]
}
```
--------------------------------
### Start React Frontend
Source: https://docs.api.video/vod/video-download
Command to start the React frontend from the React project directory.
```bash
$ npm start
```
--------------------------------
### Install Migration Dependencies
Source: https://docs.api.video/get-started/aws-migration
Installs the necessary Node.js modules for interacting with AWS S3 and api.video.
```bash
$ npm install @aws-sdk/client-s3 --save
$ npm install @aws-sdk/s3-request-presigner --save
$ npm install @api.video/nodejs-client --save
```
--------------------------------
### Response Example: Get Discarded Video
Source: https://docs.api.video/reference/api/Videos
Example JSON response for retrieving details of a discarded video object.
```json
{
"videoId": "vi4blUQJFrYWbaG44NChkH27",
"playerId": "pl45KFKdlddgk654dspkze",
"title": "Maths video",
"description": "An amazing video explaining string theory",
"public": false,
"panoramic": false,
"mp4Support": true,
"tags": [
"maths",
"string theory",
"video"
],
"metadata": [
{
"key": "Author",
"value": "John Doe"
},
{
"key": "Format",
"value": "Tutorial"
}
],
"publishedAt": "2019-12-16T08:25:51+00:00",
"updatedAt": "2019-12-16T08:48:49+00:00",
"discarded": true,
"discardedAt": "2024-10-16T08:48:49+00:00",
"deletesAt": "2024-11-16T08:48:49+00:00",
"source": {
"uri": "/videos/vi4blUQJFrYWbaG44NChkH27/source"
},
"assets": null
}
```
--------------------------------
### Install JARs manually
Source: https://docs.api.video/sdks/api-clients/apivideo-java-client
Then manually install the following JARs:
```bash
target/java-api-client-1.4.7.jar
target/lib/*.jar
```
--------------------------------
### Get Video Request Example (Go)
Source: https://docs.api.video/reference/api/Videos
Example of how to retrieve video details using the Go client library.
```go
// First install the go client with "go get github.com/apivideo/api.video-go-client"
// Documentation: https://github.com/apivideo/api.video-go-client/blob/main/docs/VideosApi.md#get
package main
import (
"context"
"fmt"
"os"
apivideosdk "github.com/apivideo/api.video-go-client"
)
func main() {
client := apivideosdk.ClientBuilder("YOUR_API_KEY").Build()
// if you rather like to use the sandbox environment:
// client := apivideosdk.SandboxClientBuilder("YOUR_SANDBOX_API_KEY").Build()
videoId := "videoId_example" // string | The unique identifier for the video you want details about.
res, err := client.Videos.Get(videoId)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `Videos.Get``: %v\n", err)
}
// response from `Get`: Video
fmt.Fprintf(os.Stdout, "Response from `Videos.Get`: %v\n", res)
}
```
--------------------------------
### Installation with npm
Source: https://docs.api.video/sdks/api-clients/apivideo-nodejs-client
Install the Node.js client using npm.
```bash
npm install @api.video/nodejs-client --save
```
--------------------------------
### Adding File Handler and CORS
Source: https://docs.api.video/vod/get-started-in-5-minutes
Sets up Multer for file uploads, CORS for cross-domain requests, and Body-Parser for request body parsing.
```javascript
const express = require('express');
const ApiVideoClient = require('@api.video/nodejs-client')
const app = express()
const multer = require('multer');
const bodyParser = require('body-parser');
const cors = require('cors')
const port = 5500
let upload = multer({ dest: 'upload' })
app.use(cors())
app.use(bodyParser.json())
```
--------------------------------
### Installation with yarn
Source: https://docs.api.video/sdks/api-clients/apivideo-nodejs-client
Install the Node.js client using yarn.
```bash
yarn add @api.video/nodejs-client
```
--------------------------------
### Java Request Example
Source: https://docs.api.video/reference/api/Analytics
Example of how to make a request to the analytics API using Java to get metrics breakdown with filters.
```java
FilterBy2 filterBy = new FilterBy2();
filterBy.setBrowser(Collections.singletonList("Chrome"));
filterBy.setContinent(Arrays.asList(FilterBy2.ContinentEnum.NA, FilterBy2.ContinentEnum.EU));
filterBy.setMediaType(FilterBy2.MediaTypeEnum.VIDEO);
filterBy.setTag("test");
Page res = apiClient.analytics().getMetricsBreakdown("play", "media-id").filterBy(filterBy).pageSize(30).execute();
for (AnalyticsMetricsBreakdownResponseData item : res.getItems()) {
System.out.println(item.getDimensionValue() + ": " + item.getMetricValue());
}
```
--------------------------------
### Create a video from a URL
Source: https://docs.api.video/vod/video-best-practices
Example of creating a video by providing a source URL. The service will ingest the video asynchronously.
```shell
$ curl https://ws.api.video/videos \
-H 'Authorization: Bearer {access_token} \n
-d '{"source":"http://uri/to/video.mp4", "title":"My video"}'"
```
--------------------------------
### Java Request Example
Source: https://docs.api.video/reference/api/Analytics
Example of how to construct a request to get aggregated metrics using the Java SDK, with filtering options.
```java
FilterBy2 filterBy = new FilterBy2();
filterBy.setBrowser(Collections.singletonList("Chrome"));
filterBy.setContinent(Arrays.asList(FilterBy2.ContinentEnum.NA, FilterBy2.ContinentEnum.EU));
filterBy.setMediaType(FilterBy2.MediaTypeEnum.VIDEO);
filterBy.setTag("test");
AnalyticsAggregatedMetricsResponse res = apiClient.analytics().getAggregatedMetrics("play", "total").filterBy(filterBy).execute();
System.out.println(res.getData());
```
--------------------------------
### Manual JAR installation
Source: https://docs.api.video/sdks/api-clients/apivideo-android-client
At first generate the JAR by executing:
Then manually install the following JARs:
```bash
mvn clean package
```
```bash
target/android-api-client-1.6.7.jar
target/lib/*.jar
```