api-portainer
TypeScript icon, indicating that this package has built-in type declarations

0.3.4 • Public • Published

Portainer Client

This projects exposes the Portainer API (currently for version 1.20.2) as Promise-based JavaScript functions. Currently, only GET based endpoints are implemented, other ones will follow. If I have enough time and motivation, I will also add an OOP abstraction layer.

The package is written in TypeScript (.d.ts type definitions come bundled with this package) and compiles to ES5.

Table of contents

Features

  • Call Portainer API endpoints using plain JS functions or a class
  • Optional encapsulation of authentication and hostname using the PortainerSession class

Example

Using the plain functions

const host = 'https://myportainerinstance';

async function main() {
    const token = await authenticate(host, 'username', 'password');
    const stacks = await stacks.getAll(host, token);
    console.log(JSON.stringify(stacks));
}

main();
$ node index.js
[{"Id":3,"Name":"databasestack","Type":2,"EndpointId":1,"SwarmId":"","EntryPoint":"docker-compose.yml","Env":[],"ProjectPath":"/data/compose/3","ResourceControl":{"Id":0,"ResourceId":"","SubResourceIds":null,"Type":0,"UserAccesses":null,"TeamAccesses":null,"Public":false}}]

Using the PortainerSession class

import PortainerSession from 'portainer-client';

async function main() {
    const portainer = await PortainerSession.create('https://portainer.example.com','username', 'password');

    const stacks = await portainer.getStacks();
    console.log(JSON.stringify(stacks));
}
$ node index.js
[{"Id":3,"Name":"databasestack","Type":2,"EndpointId":1,"SwarmId":"","EntryPoint":"docker-compose.yml","Env":[],"ProjectPath":"/data/compose/3","ResourceControl":{"Id":0,"ResourceId":"","SubResourceIds":null,"Type

Readme

Keywords

none

Package Sidebar

Install

npm i api-portainer

Weekly Downloads

2

Version

0.3.4

License

MIT

Unpacked Size

79 kB

Total Files

35

Last publish

Collaborators

  • sajadam98