Skip to content

Commit

Permalink
Add template get all and get by id examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Shillitto committed Apr 16, 2023
1 parent 137ce82 commit eb68f39
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
- **templates/render.js**
Render a template using merge fields to replace placeholders.

- **templates/templates.js**
Get a list of all templates.

- **templates/templates.js**
Get an individual template by template ID.

### Polling example

- **status.js** -
Expand Down
32 changes: 32 additions & 0 deletions examples/templates/template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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);
});
30 changes: 30 additions & 0 deletions examples/templates/templates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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);
});
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eb68f39

Please sign in to comment.