Javascript

Javascript Example

Headers

Name
Value

Content-Type

application/json

Authorization

Key <token>

Body

Name
Description

licenseKey

License key provided by the bot.

productName

Name of the product.

version

Current product version.

userId

Customer discord user Id.

hwid

Hardware Id of the user.

const licenseKey = "";
const productName = "";
const version = "";
const userId = "";
const token = "";
const hwid = getHwId();

const res = await fetch("http://<DOMAIN>:<PORT>/api/v1/key", {
    method: "POST",
    headers: {
        "Authorization": "Key " + token,
        "Content-Type": "application/json"
    },
    body: "{\"licenseKey\": \"" + licenseKey + "\",\"product\": \"" + productName + "\",\"version\": \"" + version + "\",\"hwid\": \"" + hwid + "\",\"userId\": \"" + userId + "\"}"
});

const response = await res.text();
const parsedText = JSON.parse(response);

if (parsedText && [400, 403, 404].includes(parsedText.statusCode)) {
    setTimeout(() => {
        console.execute(`Validation failed ⟶  ` + "\x1b[0m" + "( " + "\x1b[31m" + licenseKey + "\x1b[0m" + " )");
        console.log(" ");
        console.execute("Reason: " + "\x1b[0m" + "( " + "\x1b[31m" + `❌ ${parsedText.message}` + "\x1b[0m" + " )");
        return process.exit(1);
    }, 3500);
} else if (parsedText && [200].includes(parsedText.statusCode)) {
    setTimeout(() => {
        console.execute(`License validated ⟶  ` + "\x1b[0m" + "( " + "\x1b[38;5;36m" + licenseKey + "\x1b[0m" + " )");
        console.log(" ");
        console.execute("Message: " + "\x1b[0m" + "( " + "\x1b[38;5;36m" + `✅ You can now use: ${client.user.username}` + "\x1b[0m" + " )");
    }, 3500);
} else {
    setTimeout(() => {
        console.execute(`Validation failed ⟶  ` + "\x1b[0m" + "( " + "\x1b[31m" + licenseKey + "\x1b[0m" + " )");
        console.log(" ");
        console.execute("Reason: " + "\x1b[0m" + "( " + "\x1b[31m" + `❌ ${parsedText.message}` + "\x1b[0m" + " )");
        return process.exit(1);
    }, 3500);
}

Get HwId

Dependencies

npm install child_process
const { execSync } = require("child_process");

function getHwId() {
    const platforms = {
        win32: [
            "REG QUERY HKLM\\SOFTWARE\\Microsoft\\Cryptography /v MachineGuid",
            /MachineGuid\s+REG_SZ\s+(.*?)\s/
        ],
        darwin: [
            "ioreg -rd1 -c IOPlatformExpertDevice",
            /"IOPlatformUUID" = "(.*?)"/
        ],
        linux: [
            "cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || true",
            /^([\da-f]+)/
        ]
    }

    const getPlatform = platforms[process.platform];
    if (!getPlatform) return;
    const result = getPlatform[1].exec(execSync(getPlatform[0]).toString());
    if (!result) return;
    return result[1] || undefined;
};

Last updated