-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcreate_contact.js
36 lines (32 loc) · 1 KB
/
create_contact.js
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
36
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 contactDetails = {
label: 'Alice Appleseed (US)',
email: '[email protected]',
first_name: 'Alice',
last_name: 'Appleseed',
address1: '111 SW 1st Street',
city: 'Miami',
state_province: 'FL',
postal_code: '11111',
country: 'US',
phone: '+1 321 555 4444',
};
const contact = await dnsimple.contacts.createContact(accountId, contactDetails);
console.log(contact);
} catch (err) {
if (err instanceof AuthenticationError) {
console.error('Authentication error. Check your token is correct for the sandbox environment.');
} else {
console.error(err);
}
}
})();