PHP code example of fastpix / sdk

1. Go to this page and download the library: Download fastpix/sdk 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/ */

    

fastpix / sdk example snippets



FastPix\Sdk;

echo "FastPix SDK loaded successfully" . PHP_EOL;


FastPix\Sdk;
use FastPix\Sdk\Models\Components;

$username = getenv('FASTPIX_USERNAME');
$password = getenv('FASTPIX_PASSWORD');

if ($username === false || $username === '') {
    throw new RuntimeException('FASTPIX_USERNAME is not set');
}
if ($password === false || $password === '') {
    throw new RuntimeException('FASTPIX_PASSWORD is not set');
}

$sdk = Sdk\Fastpixsdk::builder()
    ->setSecurity(
        new Components\Security(
            username: $username,
            password: $password,
        )
    )
    ->build();

echo "FastPix client initialized" . PHP_EOL;

$sdk->inputVideo->createMedia(...)

$sdk->inputVideo->createMedia()


FastPix\Sdk;
use FastPix\Sdk\Models\Components;

$username = getenv('FASTPIX_USERNAME');
$password = getenv('FASTPIX_PASSWORD');

if ($username === false || $username === '') {
    throw new RuntimeException('FASTPIX_USERNAME is not set');
}
if ($password === false || $password === '') {
    throw new RuntimeException('FASTPIX_PASSWORD is not set');
}

$sdk = Sdk\Fastpixsdk::builder()
    ->setSecurity(
        new Components\Security(
            username: $username,
            password: $password,
        )
    )
    ->build();

try {
    $request = new Components\CreateMediaRequest(
        inputs: [
            new Components\PullVideoInput(
                url: 'https://static.fastpix.com/fp-sample-video.mp4',
            ),
        ],
        metadata: [
            'source' => 'fastpix-php-demo',
        ],
    );

    $response = $sdk->inputVideo->createMedia(
        request: $request,
    );

    if ($response->statusCode >= 200 && $response->statusCode < 300) {
        $rawBody = (string) $response->rawResponse->getBody();
        $decoded = json_decode($rawBody, true);
        echo json_encode(
            $decoded ?? $rawBody,
            JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES,
        ) . PHP_EOL;
    } else {
        $errorPayload = $response->defaultError
            ?? $response->error
            ?? null;
        if ($errorPayload !== null) {
            echo json_encode(
                $errorPayload,
                JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES,
            ) . PHP_EOL;
        } else {
            echo json_encode(
                ['message' => 'No response data'],
                JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES,
            ) . PHP_EOL;
        }
        exit(1);
    }
} catch (\Exception $e) {
    echo json_encode(
        ['error' => $e->getMessage()],
        JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES,
    ) . PHP_EOL;
    exit(1);
}



declare(strict_types=1);

k\Models\Components;

$sdk = Sdk\Fastpixsdk::builder()
    ->setSecurity(
        new Components\Security(
            username: 'your-access-token',
            password: 'your-secret-key',
        )
    )
    ->build();

try {
    $request = new Components\CreateMediaRequest(
        inputs: [new Components\PullVideoInput(url: 'https://static.fastpix.com/fp-sample-video.mp4')],
        metadata: ['key1' => 'value1'],
    );

    $response = $sdk->inputVideo->createMedia(request: $request);

    if ($response->createMediaSuccessResponse !== null) {
        $rawBody = (string) $response->rawResponse->getBody();
        $decoded = json_decode($rawBody, true);
        echo json_encode($decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
    }
} catch (\FastPix\Sdk\Models\Errors\APIException $e) {
    echo "Error: " . $e->getMessage() . "\n";
    echo "Status: " . $e->statusCode . "\n";
    echo "Body: " . $e->body . "\n";
}



declare(strict_types=1);

k\Models\Components;

$sdk = Sdk\Fastpixsdk::builder()
    ->setServerUrl('https://api.fastpix.com/v1/')
    ->setSecurity(
        new Components\Security(
            username: 'your-access-token',
            password: 'your-secret-key',
        )
    )
    ->build();
bash
php --version
text
PHP 8.5.10 (cli) ...
bash
php -r 'echo PHP_VERSION, PHP_EOL;'
bash
which composer
bash
mkdir fastpix-php-demo
cd fastpix-php-demo
text
fastpix-php-demo/
└── composer.json
text
fastpix-php-demo/
├── composer.json
├── composer.lock
└── vendor/
bash
php verify.php
text
FASTPIX_USERNAME → Access Token
FASTPIX_PASSWORD → Secret Key
bash
if [ -n "$FASTPIX_USERNAME" ]; then
  echo "Access Token: set"
else
  echo "Access Token: missing"
fi

if [ -n "$FASTPIX_PASSWORD" ]; then
  echo "Secret Key: set"
else
  echo "Secret Key: missing"
fi
bash
php main.php
bash
php main.php