node-updown
v1.0.2
Published
Transparent Node.JS wrapper for the updown.io API
Downloads
7
Maintainers
Readme
node-updown
Transparent Node.js wrapper for the updown.io API
Uses cross-fetch
so should work in browsers and in node.
yarn add node-updown
Usage
There are two ways to use the library:
Client
import { UpdownClient } from 'node-updown';
// Create the client with your API key (readonly or full access)
const client = new UpdownClient('API_KEY');
// Use one of the methods to interact with the API
let check = await client.getCheck('TOKEN');
This is the recommended way to use if you need to make lots of API calls, or if you have a long-running application (e.g. a server).
Functional
import { getCheck } from 'node-updown';
// Use the API function directly, by adding your API key
let check = await getCheck('API_KEY', 'TOKEN');
This is useful if you only need to make one or two API calls, or if you want to limit the size of your bundle by tree-shaking the unused functions.
API
In this documentation, we'll use the client instance. To use the functional API, simply add your API key as the first argument. So client.getCheck(token)
becomes getCheck(apiKey, token)
.
The API is kept as transparent as possible, so all values and options should mirror the Updown API documentation closely. Consult the API docs to see the returned data for each call.
Tokens are always required, most other settings are optional unless listed otherwise. All functions operating on an entity will take the entity ID/token as a first parameter (or second, if you're using the functional API) and an options object containing the remaining parameters.
The library is entirely promise-based.
Time strings should be in one of the supported formats.
Get checks
client.getChecks();
Get check
client.getCheck(token);
Get downtimes
client.getDowntimes(token, { page });
page
(number): the page to fetch, default 1
Get metrics
client.getMetrics(token, { from, to, group });
from
(time): start time, default 1 month agoto
(time): end time, default nowgroup
(string): group data by hour ('time'
) or by monitoring location ('host'
)
Add check
client.addCheck(params);
See the API docs for the full list of parameters
Update check
client.updateCheck(token, params);
See the API docs for the full list of parameters
Delete check
client.deleteCheck(token);
Get monitoring nodes
client.getNodes();
Note: this function does not require an API key
Get IP addresses of monitoring nodes
client.getIpv4Nodes();
client.getIpv6Nodes();
Note: these functions do not require an API key
Get webhooks
client.getWebhooks();
Add webhook
client.addWebhook({ url });
url
(string): the URL of the webhook
Delete webhook
client.deleteWebhook(id);
id
(string): ID of the webhook you want to delete
Issues
If you experience any bugs or errors, or if you have any questions about how to use this library, be sure to create an issue.
LICENSE
This package is licensed under the MIT license.