doapi
The doapi module allows you to communicate with the DigitalOcean API V2 from node.js in a promise friendly manner.
It also supports automatic request retries.
Installation
This module is published in NPM:
npm install doapi --save
The --save
tells NPM to automatically add it to your package.json
file
Usage
var DigitalOceanAPI = require('doapi');
var api = new DigitalOceanAPI({token: 'my_token'});
api.dropletGetAll().then(function (droplets) {
console.log(droplets);
});
Config
new DigitalOceanAPI({
token: 'my_token',
itemsPerPage: 100,
maxRetries: 5,
raw: false
});
you can pass pagination params into any method that has a body
or query
argument.
api.dropletGetAll({per_page: 1, page: 2}).then(function (droplets) {
console.log(droplets);
});
Raw
if you set raw it will return the full response body with request info
and ratelimiting details
, the default is false.
api.accountGet(true)
would return
{
account: {
droplet_limit: 25,
email: 'email@domain.com',
uuid: 'f5bbaffce3a8792421593a7075b486bafd66672f',
email_verified: true
},
ratelimit: {
limit: '5000',
remaining: '4993',
reset: '1434197547'
},
requestinfo: {
id: 'a24427fd-0d43-9536-a206-zac22d2696e1',
runtime: '0.038537'
}
}
and with raw set to false (the default), it would return
{
droplet_limit: 25,
email: 'email@domain.com',
uuid: 'f5bbaffce3a8792421593a7075b486bafd66672f',
email_verified: true
}
Debugging
we use the debug module so you can debug the http requests by doing the following
DEBUG=http node myfile.js
also all methods enforce type checking so invalid usage would result in errors like this
Methods
All methods follow the official API documentation.
Droplets
- dropletGetAll(Object query [, Boolean raw])
- dropletNew(Object body, [, Boolean raw])
- dropletGet(Number id [, Boolean raw])
- dropletReboot(Number id [, Boolean raw])
- dropletPowerCycle(Number id [, Boolean raw])
- dropletShutdown(Number id [, Boolean raw])
- dropletPowerOff(Number id [, Boolean raw])
- dropletPowerOn(Number id [, Boolean raw])
- dropletPasswordReset(Number id [, Boolean raw])
- dropletResize(Number id, Object body [, Boolean raw])
- dropletSnapshot(Number id, Object body [, Boolean raw])
- dropletRestore(Number id, Object body [, Boolean raw])
- dropletRebuild(Number id, Object body [, Boolean raw])
- dropletRename(Number id, Object body [, Boolean raw])
- dropletDestroy(Number id [, Boolean raw])
- dropletKernalsGetAll(Number id, Object query [, Boolean raw])
- dropletSnapshotsGetAll(Number id, Object query [, Boolean raw])
- dropletBackupsGetAll(Number id, Object query [, Boolean raw])
- dropletActionGetAll(Number id, Object query [, Boolean raw])
- dropletNeighborsGetAll(Number id, Object query [, Boolean raw])
- dropletUpgradesGetAll(Object query [, Boolean raw])
- reportDropletNeighborsGetAll(Object query [, Boolean raw])
Account
Regions
Images
SSH keys
Sizes
Domains
- domainGetAll(Object query [, Boolean raw])
- domainNew(String name, Object body [, Boolean raw])
- domainGet(String name [, Boolean raw])
- domainDestroy(String name [, Boolean raw])
- domainRecordGetAll(String name, Object query [, Boolean raw])
- domainRecordNew(String name, Object body [, Boolean raw])
- domainRecordGet(String name, Number id [, Boolean raw])
- domainRecordEdit(String name, Number id, Object body [, Boolean raw])
- domainRecordDestroy(String name, Number id [, Boolean raw])
Actions
Floating IPs