-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathapply_template.js
More file actions
35 lines (30 loc) · 1022 Bytes
/
apply_template.js
File metadata and controls
35 lines (30 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const { DNSimple, AuthenticationError } = require('dnsimple');
(async () => {
const dnsimple = new DNSimple({
baseUrl: 'https://api.sandbox.dnsimple.com',
accessToken: process.env.TOKEN,
userAgent: 'dnsimple-examples',
});
try {
const identity = await dnsimple.identity.whoami();
const accountId = identity.data.account.id;
const domainName = process.env.DOMAIN;
const templateId = process.env.templateID;
if (!domainName) {
console.error('Please specify a domain name to register');
return;
}
if (!templateId) {
console.error('Please specify a template ID to register the domain with');
return;
}
const response = await dnsimple.templates.applyTemplate(accountId, domainName, templateId);
console.log(response);
} catch (err) {
if (err instanceof AuthenticationError) {
console.error('Authentication error. Check your token is correct for the sandbox environment.');
} else {
console.error(err);
}
}
})();