PHP API client

PHP API client for api.video service (beta version)

api.video PHP API client

api.video is an API that encodes on the go to facilitate immediate playback, enhancing viewer streaming experiences across multiple devices and platforms. You can stream live or on-demand online videos within minutes.

Installation

composer require api-video/php-api-client

Initialize api.video client

Due to PHP PSR support, you must initialize the client with 3 to 5 arguments:

  1. Base URI, which can be either https://sandbox.api.video or https://ws.api.video
  2. Your API key, available on your account
  3. HTTP client
  4. (Request factory)
  5. (Stream factory)

Note : If the HTTP client also implements RequestFactoryInterface and StreamFactoryInterface, then it is not necessary to pass this object in 4th and 5th argument.

Symfony HTTP client example

The Symfony HTTP client has the triple advantage of playing the role of HTTP client, but also of request factory and stream factory. It is therefore sufficient to pass it as an argument 3 times.

$httpClient = new \Symfony\Component\HttpClient\Psr18Client();
$client = new \ApiVideo\Client(
    'https://sandbox.api.video',
    'YOUR_API_TOKEN',
    $httpClient
);

Public endpoints

Some endpoints don't require authentication. These one can be called with a Client instantiated with a null API token:

$httpClient = new \Symfony\Component\HttpClient\Psr18Client();
$client = new \ApiVideo\Client(
    'https://sandbox.api.video',
    null,
    $httpClient
);

Cookbook

In the following examples the $client must already be initialized.

Create a video

$payload = (new VideoCreationPayload())
    ->setTitle('Test video creation');

$video = $client->videos()->create($payload);

Upload a video

$payload = (new VideoCreationPayload())
    ->setTitle('Test video creation');

$video = $client->videos()->create($payload);

$this->client->videos()->upload(
    $video->getVideoId(),
    new SplFileObject(__DIR__.'/../earth.mp4')
);

Chunks

The video is automatically split into 1 Mb chunks.

To modify the size of the chunks, fill in the last argument $contentRange as follows:

  • bytes 0-{size}/0 where {size} is the size of the chunk.

For example : bytes 0-500000/0 for 500 Kb chunks.

API Endpoints

All URIs are relative to https://ws.api.video.

CaptionsApi

Retrieve an instance of CaptionsApi

// The $client must already be initialized
$captions = $client->captions();

Endpoints

MethodHTTP requestDescription
deleteDELETE /videos/{videoId}/captions/{language}Delete a caption
listGET /videos/{videoId}/captionsList video captions
getGET /videos/{videoId}/captions/{language}Show a caption
updatePATCH /videos/{videoId}/captions/{language}Update caption
uploadPOST /videos/{videoId}/captions/{language}Upload a caption

ChaptersApi

Retrieve an instance of ChaptersApi

// The $client must already be initialized
$chapters = $client->chapters();

Endpoints

MethodHTTP requestDescription
deleteDELETE /videos/{videoId}/chapters/{language}Delete a chapter
listGET /videos/{videoId}/chaptersList video chapters
getGET /videos/{videoId}/chapters/{language}Show a chapter
uploadPOST /videos/{videoId}/chapters/{language}Upload a chapter

LiveStreamsApi

Retrieve an instance of LiveStreamsApi

// The $client must already be initialized
$liveStreams = $client->liveStreams();

Endpoints

MethodHTTP requestDescription
deleteDELETE /live-streams/{liveStreamId}Delete a live stream
deleteThumbnailDELETE /live-streams/{liveStreamId}/thumbnailDelete a thumbnail
listGET /live-streamsList all live streams
getGET /live-streams/{liveStreamId}Show live stream
updatePATCH /live-streams/{liveStreamId}Update a live stream
createPOST /live-streamsCreate live stream
uploadThumbnailPOST /live-streams/{liveStreamId}/thumbnailUpload a thumbnail

PlayerThemesApi

Retrieve an instance of PlayerThemesApi

// The $client must already be initialized
$playerThemes = $client->playerThemes();

Endpoints

MethodHTTP requestDescription
deleteDELETE /players/{playerId}Delete a player
deleteLogoDELETE /players/{playerId}/logoDelete logo
listGET /playersList all players
getGET /players/{playerId}Show a player
updatePATCH /players/{playerId}Update a player
createPOST /playersCreate a player
uploadLogoPOST /players/{playerId}/logoUpload a logo

RawStatisticsApi

Retrieve an instance of RawStatisticsApi

// The $client must already be initialized
$rawStatistics = $client->rawStatistics();

Endpoints

MethodHTTP requestDescription
listLiveStreamSessionsGET /analytics/live-streams/{liveStreamId}List live stream player sessions
listSessionEventsGET /analytics/sessions/{sessionId}/eventsList player session events
listVideoSessionsGET /analytics/videos/{videoId}List video player sessions

UploadTokensApi

Retrieve an instance of UploadTokensApi

// The $client must already be initialized
$uploadTokens = $client->uploadTokens();

Endpoints

MethodHTTP requestDescription
deleteTokenDELETE /upload-tokens/{uploadToken}Delete an upload token
listGET /upload-tokensList all active upload tokens.
getTokenGET /upload-tokens/{uploadToken}Show upload token
createTokenPOST /upload-tokensGenerate an upload token

VideosApi

Retrieve an instance of VideosApi

// The $client must already be initialized
$videos = $client->videos();

Endpoints

MethodHTTP requestDescription
deleteDELETE /videos/{videoId}Delete a video
getGET /videos/{videoId}Show a video
getStatusGET /videos/{videoId}/statusShow video status
listGET /videosList all videos
updatePATCH /videos/{videoId}Update a video
pickThumbnailPATCH /videos/{videoId}/thumbnailPick a thumbnail
uploadWithUploadTokenPOST /uploadUpload with an upload token
createPOST /videosCreate a video
uploadPOST /videos/{videoId}/sourceUpload a video
uploadThumbnailPOST /videos/{videoId}/thumbnailUpload a thumbnail

WebhooksApi

Retrieve an instance of WebhooksApi

// The $client must already be initialized
$webhooks = $client->webhooks();

Endpoints

MethodHTTP requestDescription
deleteDELETE /webhooks/{webhookId}Delete a Webhook
getGET /webhooks/{webhookId}Show Webhook details
listGET /webhooksList all webhooks
createPOST /webhooksCreate Webhook

Models

Tests

In order to run the PhpUnit tests, it is necessary to enter two variables in the command line:

  • BASE_URI (for example : https://sandbox.api.video)
  • API_KEY

These identifiers must belong to a real Api.video account.

$ BASE_URI="" API_KEY="..." vendor/bin/phpunit

Did this page help you?