PHP SDK
Official PHP SDK for the JSON2Video REST API.
- Repository: github.com/JSON2Video/json2video-php-sdk
- Composer package:
json2video/json2video-php-sdk
Install
composer require json2video/json2video-php-sdk
Minimal example
<?php
require __DIR__ . '/vendor/autoload.php';
use Json2Video\Movie;
$movie = new Movie();
$movie->setAPIKey(getenv('J2V_API_KEY'));
$movie->setResolution('full-hd');
$scene = $movie->addScene();
$scene->addElement([
'type' => 'text',
'text' => 'Hello, JSON2Video',
'duration' => 5,
'style' => '001',
]);
$result = $movie->render(); // Submits POST /v2/movies.
$status = $movie->getStatus(true); // Polls GET /v2/movies until done.
echo $status['movie']['url'];
Configuration
| Method | Purpose |
|---|---|
setAPIKey($key) |
Sets the x-api-key header. |
setResolution($preset) |
Convenience wrapper for movie.resolution. |
setQuality($q) |
Convenience wrapper for movie.quality. |
addScene() |
Appends a scene; returns a Scene builder. |
addElement($element) |
Adds a top-level (movie-wide) element. |
render() |
Submits the movie and returns the API response. |
getStatus($wait = false) |
Calls GET /v2/movies. With true, polls until completion. |
The SDK transparently maps method calls to the JSON shape documented in Movie JSON.
Error handling
API failures throw exceptions with the HTTP status and message body. See Errors for the full list.