Wistia file upload using Upload API

Wistia a professional video hosting with great analytics and video marketing tools. It has tons of features along with prompt customer support. What it lacks though is a great developer community. And surprisingly, Wistia does not officially support PHP developers for API integrations.

It does not even have a PHP team for it? I mean, who does that! And they don’t plan to have one in near future if my emails with their support rep is to be trusted.

But, with that being said, they do have a great product and i will today be focusing on uploading videos to Wistia using PHP and Wistia Upload API.

So, like with many other APIs, we willuse PHP cURL. But first, we will needtokeep these points touse the Upload API.

  • Use POST method
  • Use SSL-based API endpoint (https://upload.wistia.com/)
  • Upload will only be successful if the data is multipart-form encoded

Required post parameters

Two parameters are required:

  1. api_password or access_token
  2. file (If uploading from local source or a newfile) or url (From an external source) 

Apart from these, you can optionally pass in project_id, name, description and contact_id.

 Now, to upload a file you will need to create a PHP based cURL request as below.

The $resultJson here is the object representation of json result returned from  Wistia after successful upload. Notice i used the CurlFile class instead of trying to encode the upload content explicitly. But beware that CurlFile is only native to PHP version > 5.5.

Here is a sample json response return from Wistia:

Here, hashed_id is the field you might wanna save in DB since it is also required to update and delete media from Wistia.

If there is an error, you will see something like below in json response:

Wistia resturns HTTP 200 header upon successful upload and 400 for errors. Also, it returns 401 when there is an authentication error.

alexey

Application developer, movie buff, occasional reader and a huge Manchester United fan.
alexey

Application developer, movie buff, occasional reader and a huge Manchester United fan.