cPanel API JavaScript and TypeScript interface libraries.
This library provides a set of classes for calling cPanel WHM API 1 and UAPI calls. The classes hide much of the complexity of these API's behind classes that abstract the underlying variances between these API systems. Users of this library can focus on what they want to accomplish rather than having to learn the various complexities of the underlying wire formats for each of the cPanel product's APIs.
To install these libraries with NPM, run:
npm install @cpanel/api
import {
Argument,
WhmApiResponse,
WhmApiRequest,
WhmApiType,
WhmApiTokenHeader,
} from "@cpanel/api";
const token = "...paste your API token here...";
const request = new WhmApiRequest(WhmApiType.JsonApi, {
method: "api_token_create",
arguments: [
new Argument("token_name", "my-Auth-Token"),
// ---- API Token Permissions ----
// Login to the UI
new Argument("acl", "create-user-session"),
// Delete a token
new Argument("acl", "manage-api-tokens"),
],
headers: [new WhmApiTokenHeader(token, "root")],
}).generate();
fetch("http://my-cpanel-server.com:2087", {
method: "POST",
headers: request.headers.toObject(),
body: request.body,
})
.then((response) => response.json())
.then((response) => {
response.data = new WhmApiResponse(response.data);
if (!response.data.status) {
throw new Error(response.data.errors[0].message);
}
return response;
})
.then((data) => console.log(data));
let {
Argument,
WhmApiResponse,
WhmApiRequest,
WhmApiType,
WhmApiTokenHeader
} = require("@cpanel/api");
const token = "...paste your API token here...";
const request = new WhmApiRequest(WhmApiType.JsonApi, {
method: "api_token_create",
arguments: [
new Argument('token_name', 'my-Auth-Token'),
// ---- API Token Permissions ----
// Login to the UI
new Argument('acl', 'create-user-session'),
// Delete a token
new Argument('acl', 'manage-api-tokens'),
],
headers: [
new WhmApiTokenHeader(token, 'root'),
],
}).generate();
fetch('http://my-cpanel-server.com:2087', {
method: 'POST',
headers: request.headers.toObject()),
body: request.body
})
.then(response => response.json())
.then(response => {
response.data = new WhmApiResponse(response.data);
if(!response.data.status) {
throw new Error(response.data.errors[0].message);
}
return response;
})
.then(data => console.log(data));
-
Set up your development environment to test the local version of your library rather than the one distributed on
npm.dev.cpanel.net
:npm install --also=dev npm run build:dev
-
Make the changes to the library.
-
Rebuild the library:
npm run build:dev
To install the development dependencies, run:
npm install --also=dev
npm run test
The maintainer will evaluate all bugs and feature requests, and reserves the right to reject a request for any reason.
Please submit bugs via the github issue tracker. Bug reports must include the following:
- The version of the @cpanel/api library.
- The version of cPanel & WHM you are testing against.
- A step by step set of instructions on how to reproduce the bug.
- Sample code that reproduces the bug.
The maintainers will evaluate all bugs.
Please submit feature requests via the github issue tracker.
Describe the feature in detail. Try to include information on why the suggested feature would be valuable and under what scenarios.
We welcome pull requests against the @cpanel/api library.
The maintainers will evaluate all pull requests. Pull requests are subject to review by the maintainers. We may request additional adjustments to any submitted pull requests.
Any code submitted via pull requests that is incorporated into the library will become the property of cPanel L.L.C. and will be published under the cPanel L.L.C. copyright and the MIT license.
Note Publishing is limited to select cPanel maintainers.
When your changes are implemented and tested, and you're ready to publish, run:
- As part of the development changes update the
version
property inpackage.json
to the formatX.X.X-alpha.X
so that the semver is updated correctly and appended with alpha build information (1.0.0 -> 1.0.1-alpha.1). npm run publish
- Confirm changes are properly published at http://alpha.docs.ui.dev.cpanel.net/locale
- When dev changes are accepted and complete update the
version
property inpackage.json
to the formatX.X.X
so that the semver is updated correctly and alpha build information has been removed. Do this on the development branch before merging pull request (1.0.1-alpha.1 -> 1.0.1). npm run publish
- Team Phoenix @ cPanel
- Team Artemis @ cPanel
- Team Cobra @ cPanel
- Team Moonshot @ cPanel
- Thomas Green tomg@cpanel.net
- Sruthi Sanigarapu sruthi@cpanel.net
- Aneece Yazdani aneece@cpanel.net
- Sarah Kiniry sarah.kiniry@cpanel.net
- Dustin Scherer dustin.scherer@cpanel.net
- Philip King phil@cpanel.net
- Caitlin Flattery c.flattery@cpanel.net
- Aspen Hollyer a.hollyer@cpanel.net
Copyright © 2022 cPanel, L.L.C. Licensed under the included MIT license.