A PluralKit API wrapper for NodeJS, written in TypeScript
PluralKit is an incredibly useful tool for plurals, trans folks, and roleplayers that comes with an API for use alongside the bot. This wrapper was created to make interacting with the API in Node.js applications easier
This wrapper comes with features like:
- Full coverage of the API (up to v2)
- More options for setting values (eg: "red" is a valid
member.color
) - Options to fetch members, fronters, and switches when fetching a system
- Promise based and object oriented
And more!
With Node 14.x or higher, use this to install:
npm install pkapi.js
This library uses only a few dependencies, which are:
- axios - for request handling
- @vvo/tzdb - for verifying timezones
- chrono-node - for parsing birthdays
- tinycolor2 - for parsing colors
- valid-url - for verifying avatar urls
The wrapper itself requires zero setup. However, there are still some options you can use:
// cjs, or commonJS
const PKAPI = require('pkapi.js').default;
// esm
import PKAPI from 'pkapi.js';
// shown values are defaults!
const api = new PKAPI({
base_url: "https://api.pluralkit.me", // base api url
version: 2, // api version
token: undefined // for authing requests. only set if you're using this for a single system!
})
Note: This library currently supports up to APIv2.
Using the above setup; note that exmpl
is a real system
// get a system by id
var system = await api.getSystem({system: 'exmpl'});
// authed version of above
var system = await api.getSystem({system: 'exmpl', token: process.env.TOKEN});
// edit the system
system.tz = "est";
system.description = "Test system";
// patch
await system.patch(process.env.TOKEN);
// see the changes
console.log(system)
// get member
var member = await api.getMember({member: 'gaznz'};
// edit
member.name = "Test Name";
member.visibility = true; // public
member.name_privacy = false; // private
await member.patch(process.env.TOKEN)
console.log(member)
Check out the wiki for documentation