How do I get a list of available templates? Or how do I download a template given a template id?
I have looked at TemplateListResponseData but dont get the api call.
I am using the node sdk.
Thanks!
How do I get a list of available templates? Or how do I download a template given a template id?
I have looked at TemplateListResponseData but dont get the api call.
I am using the node sdk.
Thanks!
Hi,
I have just added some examples to the Node.js examples repo with how to get a list of templates and an individual template: GitHub - shotstack/node-demos: Shotstack Node demos - Edit videos in the cloud with Node and the Shotstack Video Editing API.
To get a list use the following code:
const Shotstack = require('shotstack-sdk');
const defaultClient = Shotstack.ApiClient.instance;
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
const api = new Shotstack.EditApi();
let apiUrl = 'https://api.shotstack.io/stage';
if (!process.env.SHOTSTACK_KEY) {
console.log('API Key is required. Set using: export SHOTSTACK_KEY=your_key_here');
process.exit(1);
}
if (process.env.SHOTSTACK_HOST) {
apiUrl = process.env.SHOTSTACK_HOST;
}
defaultClient.basePath = apiUrl;
DeveloperKey.apiKey = process.env.SHOTSTACK_KEY;
api.getTemplates().then((data) => {
const { templates } = data.response;
if (templates.length) {
console.log(templates);
}
}, (error) => {
console.error('Request failed: ', error);
process.exit(1);
});
That should give a regular array containing objects with the name and id of the templates.
You can then use one of the template ids using the following code:
const Shotstack = require('shotstack-sdk');
const defaultClient = Shotstack.ApiClient.instance;
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
const api = new Shotstack.EditApi();
const id = process.argv[2];
let apiUrl = 'https://api.shotstack.io/stage';
if (!id) {
console.log(">> Please provide the UUID of the template (i.e. node examples/templates/template.js 7feabb0e-b5eb-8c5e-847d-82297dd4802a)\n");
process.exit(1);
}
if (!process.env.SHOTSTACK_KEY) {
console.log('API Key is required. Set using: export SHOTSTACK_KEY=your_key_here');
process.exit(1);
}
if (process.env.SHOTSTACK_HOST) {
apiUrl = process.env.SHOTSTACK_HOST;
}
defaultClient.basePath = apiUrl;
DeveloperKey.apiKey = process.env.SHOTSTACK_KEY;
api.getTemplate(id).then((data) => {
console.log(JSON.stringify(data.response, null, 2));
}, (error) => {
console.error('Request failed: ', error);
process.exit(1);
});
Just make sure you pass it the template ID. The example above uses the command line argument like this:
node script.js<template_uuid>
Further documentation is here: Templates | Shotstack Documentation
Thanks Lucas! I’ll give it a try.
Worked like a charm. Thanks