PHP code example of werstreamtes / targetvideo-cms-client

1. Go to this page and download the library: Download werstreamtes/targetvideo-cms-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

werstreamtes / targetvideo-cms-client example snippets




erstreamtes\TargetVideoCmsClient\CmsClient;
use Werstreamtes\TargetVideoCmsClient\Config;

$client = new CmsClient(new Config(
    bearerToken: 'YOUR_TARGETVIDEO_BEARER_TOKEN',
));

$videos = $client->videos()->all(
    partnerId: 12345,
    queryParameters: [
        'page' => 1,
        'limit' => 25,
    ],
);

foreach ($videos->entries() as $entry) {
    echo $entry->videoId() . ': ' . ($entry->videoName() ?? 'unnamed') . PHP_EOL;
}



use Werstreamtes\TargetVideoCmsClient\Video\AddVideoRequest;
use Werstreamtes\TargetVideoCmsClient\Video\EditVideoRequest;
use Werstreamtes\TargetVideoCmsClient\Video\VideoCustomProperty;

$videos = $client->videos();

$created = $videos->add(new AddVideoRequest(
    partnerId: 12345,
    name: 'Example Video',
    sourceUrl: 'https://cdn.example.com/video.mp4',
    description: 'Created through the typed video API',
    credits: 'Reuters',
    tags: 'example,typed-client',
    customProperties: [
        new VideoCustomProperty('slot', 'pre-roll'),
    ],
));

$video = $videos->view($created->videoId());

$videos->edit($video->id(), new EditVideoRequest(
    name: 'Renamed Example Video',
    description: 'Updated description',
    credits: 'AP',
    clickthroughUrl: 'https://example.com/watch/' . $video->id(),
    customProperties: [
        new VideoCustomProperty('slot', 'mid-roll'),
    ],
));

$videos->delete($video->id(), 12345);



use Werstreamtes\TargetVideoCmsClient\Category\AddCategoryRequest;
use Werstreamtes\TargetVideoCmsClient\Category\AssignVideosRequest;
use Werstreamtes\TargetVideoCmsClient\Category\EditCategoryRequest;

$categories = $client->categories();

$categoryList = $categories->all(parentId: 0, queryParameters: ['page' => 1]);

foreach ($categoryList->entries() as $entry) {
    echo $entry->categoryId() . ': ' . ($entry->categoryName() ?? 'unnamed') . PHP_EOL;
}

$createdCategory = $categories->add(new AddCategoryRequest(
    name: 'Example Category',
));

$category = $categories->view($createdCategory->categoryId());

$categories->edit($category->id(), new EditCategoryRequest(
    name: 'Renamed Example Category',
    parentId: 0,
));

$categories->assignVideos(new AssignVideosRequest(
    categoryIds: [$category->id()],
    videoIds: [540690],
));

$categories->delete($category->id());



$adSources = $client->adSources()->call(
    'all',
    pathParameters: ['partner_id' => 12345],
);

$video = $client->resource('video')->call(
    'view',
    pathParameters: ['video_id' => 540690],
);

$createdVideo = $client->resource('video')->call(
    'add',
    bodyParameters: [
        'partner_id' => 12345,
        'name' => 'Example Video',
        'mp4' => 'https://cdn.example.com/video.mp4',
    ],
);

$updatedVideo = $client->resource('video')->call(
    'edit',
    pathParameters: ['video_id' => 540690],
    bodyParameters: [
        'Video' => [
            'name' => 'Renamed Example Video',
            'description' => 'Updated description from the API client',
            'clickthroughUrl' => 'https://example.com/watch/540690',
        ],
    ],
);

$analytics = $client->callOperation(
    'Topvideosdata',
    pathParameters: ['partner_id' => 12345],
    bodyParameters: [
        'from' => '2026-06-01',
        'to' => '2026-06-16',
    ],
);



use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\HttpFactory;
use Werstreamtes\TargetVideoCmsClient\CmsClient;
use Werstreamtes\TargetVideoCmsClient\Config;

$httpClient = new GuzzleClient();
$httpFactory = new HttpFactory();

$client = CmsClient::withPsr18(
    config: new Config(bearerToken: 'YOUR_TARGETVIDEO_BEARER_TOKEN'),
    httpClient: $httpClient,
    requestFactory: $httpFactory,
    streamFactory: $httpFactory,
);

$client->videos();
$client->categories();

$client->adSchedules();
$client->adSources();
$client->adUnits();
$client->adUnitTemplates();
$client->analytics();
$client->carousel();
$client->categories();
$client->exchangeRules();
$client->iabTaxonomies();
$client->livestreamChannel();
$client->livestreamSchedule();
$client->partners();
$client->players();
$client->playerTemplates();
$client->playlists();
$client->revenueDashboard();
$client->users();
$client->resource('video');
$client->resource('videos');
$client->resource('category');
$client->resource('categories');
$client->resource('adSources');
bash
docker compose run --rm php composer validate --strict
docker compose run --rm php composer lint
docker compose run --rm php composer test
bash
docker compose run --rm php php tools/generate-operations.php