Tutorials · 3 min read

Upload a video with PHP

Upload a video with the api.video PHP client

Walk through how to upload a video with the api.video PHP client

Erikka Innes

October 26, 2021

api.video offers a PHP client to make it easier for you to upload your videos. Today we'll walk through how to do this. You can always hop on over to the GitHub repository if you'd prefer to learn about the client that way too - api.video PHP client.


For this project, you'll need these things:

  • Composer - if you don't have it set up, go here to learn about it and get it installed - getcomposer.org
  • An api.video account - you can sign up here.


You'll need to install a few things using Composer:

  • The api.video PHP client - composer require api-video/php-api-client
  • Symfony HTTP client - composer require symfony/http-client
  • nyholm/psr7 - composer require nyholm/psr7

You can type composer update to make sure everything is pulled into your project and configured.

Code sample

Here is the code sample for uploading a file. You need to change 'yourAPIkey' to your key that you retrieve from the api.video dashboard after you create an account. Place the video you want to upload in the same folder as your code sample. For the sake of simplicity, this code sample hardcodes the title of the video - change VIDEO_TO_UPLOAD.mp4 to the title of your video file.


Import the client

In the first part of the code, you import the parts of the api.video PHP client you'll need. The client is more efficient when you import the endpoints you need for your code, instead of everything. You also need the HttpClient from Symfony for this implementation. So it will look like this:


Initialize the client

Next you initialize the client for use in your API calls.


Create your video payload

The next part of the code includes a video creation payload. This is a cool part of the PHP client. You can add all the metadata you'd like for your video here. Later, you're able to update your code as well. Consult the Create a video endpoint in our API reference documentation for available parameters. You capitalize them when adding them into your payload. So title becomes setTitle as shown in the code sample. Any parameters in camel case that you want to use would change a bit. For example, the docs have mp4Support, but if you are using the PHP client, you would write it as setMp4support.

When you send multiple parameters, the code would look like this:

$payload = (new VideoCreationPayload()) ->setTitle('My cool video'); $payload->setTags(['tag 1', 'tag 2']);

When you're done setting up your payload, then you use the client to send this information to api.video servers and create your video container.


Upload the video

In the last part of the video, you retrieve the video ID for the container you made and upload your video into the container. You can only upload into a container once, but you can change its metadata later if you wish. You can see whether it worked by reading the echoed response in the terminal.



Now you know the basics of uploading a video with the api.video PHP client! You can check whether your upload worked by going into your dashboard and looking in the videos section. You should see it there. If you get a note that it's still processing, give it a bit of time to get the video ready, especially for big videos.

If you have any questions or suggestion, please share them on our community forum. If you haven't created your api.video account yet, you can do that in just a few moments by follwoing this link. Happy building!

Try out more than 80 features for free

Access all the features for as long as you need.
No commitment or credit card required

Video API, simplified

Fully customizable API to manage everything video. From encoding to delivery, in minutes.

Built for Speed

The fastest video encoding platform. Serve your users globally with 140+ points of presence. 

Let end-users upload videos

Finally, an API that allows your end-users to upload videos and start live streams in a few clicks.


Volume discounts and usage-based pricing to ensure you don’t exceed your budget.