Node.js client for interacting with the Portainer HTTP API
npm install portainer-api-clientMake requests against a Portainer API, authenticating with username/password or key
import PortainerClient from 'portainer-api-client';
const portainerURL = process.env.PORTAINER_URL;
const portainerUsername = process.env.PORTAINER_USERNAME;
const portainerPassword = process.env.PORTAINER_PASSWORD;
const portainer = new PortainerClient({
url: portainerURL,
username: portainerUsername,
password: portainerPassword
});
const container = await portainer.callAPIWithKey('GET', '/api/endpoints/1/docker/containers/my_container_name/json');
console.log(Container's status is ${container.State?.Status});
import PortainerClient from 'portainer-api-client';
const portainerURL = process.env.PORTAINER_URL;
const portainerAPIKey = process.env.PORTAINER_API_KEY;
const portainerPassword = process.env.PORTAINER_PASSWORD;
const portainer = new PortainerClient({
url: portainerURL,
key: portainerAPIKey
});
const container = await portainer.callAPIWithKey('GET', '/api/endpoints/1/docker/containers/my_container_name/json');
console.log(Container's status is ${container.State?.Status});
import PortainerClient from 'portainer-api-client';
const portainerURL = process.env.PORTAINER_URL;
const portainerUsername = process.env.PORTAINER_USERNAME;
const portainerPassword = process.env.PORTAINER_PASSWORD;
const portainer = new PortainerClient({
url: portainerURL,
username: portainerUsername,
password: portainerPassword
});
let registries = await portainer.callAPIWithKey('get', '/api/registries');
registry = registries[0]
registry.Username = 'newusername';
registry.Password = 'newusername';
await portainer.callAPIWithKey('PUT', /api/registries/${registry.Id}, registry);
* Convenience functions
* Documentation