npm install digitalocean
var Api = require('digitalocean').Api;
var api = new Api('CLIENT_ID', 'API_KEY');
REST: GET /droplets/new
api.droplets.new({
name: "Droplet name",
size_id: 1,
image_id: 123,
region_id: 1,
ssh_key_ids: [1212, 343]
}, function(newDroplet) {
console.log('Created droplet:', newDroplet);
});
REST: GET /droplets/121233
var dropletId = 121233;
api.droplets.get(dropletId, function(droplet) {
console.log('Droplet #' + dropletId, droplet);
});
REST: GET /droplets/121233/reboot
var dropletId = 121233;
api.droplets.reboot(dropletId);
or another way
var dropletId = 121233;
api.droplets.get(dropletId, function(droplet) {
droplet.reboot();
});
Complete API documentation can be found at https://api.digitalocean.com/
Api.droplets.all(onSuccess)
- get all active dropletsApi.droplets.get(id, onSuccess)
- get droplet by idApi.droplets.new({name: "Name", size_id: 1, image_id: 1, region_id: 1, ssh_key_ids: [1]}, onSuccess)
- create new droplet
Droplet.id
Droplet.backups_active
Droplet.image_id
Droplet.name
Droplet.region_id
Droplet.size_id
Droplet.status
Droplet.reboot(onSuccess)
Droplet.power_cycle(onSuccess)
Droplet.shutdown(onSuccess)
Droplet.power_off(onSuccess)
Droplet.power_on(onSuccess)
Droplet.password_reset(onSuccess)
Droplet.resize({size_id: 1}, onSuccess)
Droplet.snapshot({name: "Name"}, onSuccess)
Droplet.restore({image_id: 1}, onSuccess)
Droplet.rebuild({image_id: 1}, onSuccess)
Droplet.enable_backups(onSuccess)
Droplet.disable_backups(onSuccess)
Droplet.rename({name: "New name"}, onSuccess)
Droplet.destroy(onSuccess)
Api.images.all(onSuccess)
- get all available images (global and my own)Api.images.global(onSuccess)
- get all available global imagesApi.images.my(onSuccess)
- get all my own imagesApi.images.get(id, onSuccess)
- get image by id
Image.id
Image.name
Image.distribution
Image.transfer({region_id: 1}, onSuccess)
Image.destroy(onSuccess)
Api.ssh_keys.all(onSuccess)
- get short info about my SSH keysApi.ssh_keys.get(id, onSuccess)
- get full info about specified SSH keyApi.ssh_keys.new({name: "My new key", ssh_pub_key: "ssh-rsa ... user@host"}, onSuccess)
- register new SSH key
SshKey.id
SshKey.name
SshKey.ssh_pub_key
- available only in full info
SshKey.edit({ssh_pub_key: "ssh-rsa ... user@host"}, onSuccess)
SshKey.destroy(onSuccess)
Api.sizes.all(onSuccess)
- get short info about all available instance typesApi.sizes.get(id, onSuccess)
- get full info about specified instance type
Size.id
Size.name
Size.slug
Size.cpu
- number of CPUs, available only in full infoSize.memory
- memory amount (in Mb), available only in full infoSize.cost_per_hour
- price per hour (in dollars), available only in full infoSize.disk
- disk space (in Gb), available only in full info
Api.regions.all(onSuccess)
- get all available regionsApi.regions.get(id, onSuccess)
- get region by id
Region.id
Region.name
Region.slug
Api.domains.all(onSuccess)
- get all domainsApi.domains.get(id, onSuccess)
- get domain by idApi.domains.new({name: 'example.com', ip_address: '8.8.8.8'}, onSuccess)
- create new domain
Domain.id
Domain.name
Domain.ttl
Domain.live_zone_file
Domain.error
Domain.zone_file_with_error
Domain.records
- see "Domain Records" section
Domain.destroy(onSuccess)
Domain.records.all(onSuccess)
Domain.records.get(id, onSuccess)
Domain.records.new({domain_id: 1, data: '@', record_type: 'A', name: '8.8.8.8'}, onSuccess)
DomainRecord.id
DomainRecord.domain_id
DomainRecord.record_type
DomainRecord.name
DomainRecord.data
DomainRecord.priority
DomainRecord.port
DomainRecord.weight
DomainRecord.edit({}, onSuccess)
DomainRecord.destroy(onSuccess)
Api.events.get(id, onSuccess)
Event.id
Event.action_status
Event.droplet_id
Event.event_type_id
Event.percentage
By default all error will asynchronously throw an error. To catch them
you need to handle 'error'
event:
api.images.get(12345, function() {
/* ... */
}).on('error', function(error) {
console.error(error);
});