Examples
These Node.js examples demonstrate common API operations. Additional examples are available on GitHub:
https://github.com/viewneo/viewneo-api/tree/master/examplesExample 1: Create a Website Media File
Section titled “Example 1: Create a Website Media File”Create a new media file entry with a website URL:
const request = require('request');
const access_token = 'YOUR_ACCESS_TOKEN';
var options = { url: 'https://cloud.viewneo.com/api/v1.0/mediafile', method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + access_token }, body: JSON.stringify({ name: 'viewneo', media_file_id_as_parent_directory: 0, url: 'https://www.viewneo.com' })};
request(options, (error, response, body) => { if (error) { return console.error('Error: ', error); } console.log('Response body: ' + body);});Key points:
- Uses
POSTto the/mediafileendpoint - Sets
media_file_id_as_parent_directoryto0for the root folder - The
urlfield specifies the website to embed
Example 2: Upload an Image File
Section titled “Example 2: Upload an Image File”Upload a JPEG image from the local file system:
const request = require('request');const fs = require('fs');
const access_token = 'YOUR_ACCESS_TOKEN';
var options = { url: 'https://cloud.viewneo.com/api/v1.0/mediafile', method: 'POST', headers: { 'Content-Type': 'multipart/form-data', 'Authorization': 'Bearer ' + access_token }, formData: { media_file_id_as_parent_directory: 0, file: fs.createReadStream('./src/image.jpg') }};
request(options, (error, response, body) => { if (error) { return console.error('Error: ', error); } console.log('Response body: ' + body);});Key points:
- Uses
multipart/form-datafor file uploads (not JSON) - The
filefield streams the image from disk - The same
/mediafileendpoint handles both website and file uploads
More Examples
Section titled “More Examples”Find additional examples and updates on the viewneo GitHub repository: