Skip to content
CtrlK

Examples

These Node.js examples demonstrate common API operations. Additional examples are available on GitHub:

https://github.com/viewneo/viewneo-api/tree/master/examples

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 POST to the /mediafile endpoint
  • Sets media_file_id_as_parent_directory to 0 for the root folder
  • The url field specifies the website to embed

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-data for file uploads (not JSON)
  • The file field streams the image from disk
  • The same /mediafile endpoint handles both website and file uploads

Find additional examples and updates on the viewneo GitHub repository: