Wistia is a video hosting company which provides video storage as well as analytics solutions to businesses.
I have been working with Wistia API for one of my clients for some time now and have used Wistia Data API extensively to work with their hosted videos. This post is about using Node.js to communicate with Wistia API servers using basic password authentication.
So, to achieve our goal, we need one dependency:
1 | npm install request --save |
We need the npm request module to make calls to the API.
Then, to make the actual call:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | request({ url: 'https://api.wistia.com/v1/<ENDPOINT>.json', method: '<METHOD>' }, function(error, response, body) { if (error) { return cb(error); } if (response.statusCode == 200 || response.statusCode == 201) { return cb(null, body); } else { return cb(new Error('Server responded with error: ' + response.statusCode)); } }) |
Here ENDPOINT is the API endpoint like ‘account‘ or ‘medias’ and METHOD is the request method like GET or POST or DELETE depending on the endpoint type.
It will return json body with error or data. If the response sends any headers other than 200 or 201, it’s a failure.
We can work the same way with the Upload API, only in that case we will need to send POST data that is form-encoded.
I have created a small node wrapper for the API here that works with Data API.
alexey
Latest posts by alexey (see all)
- Zend Soap NULL Reponse - August 29, 2018
- Quick Facts About WooCommerce - April 25, 2018
- WordPress stuck on a “Too many redirects” error loop when using SSL - January 17, 2018
Recent Comments