Skip to content

Key verification

Key verification authenticates your API key before calling the comment check, submit spam or submit ham methods.

Client.verifyKey(): Promise<boolean>

This is the first call that you should make to Akismet and is especially useful if you will have multiple users with their own Akismet subscriptions using your application.

See the Akismet API documentation for more information.

Parameters

None.

Return value

A Promise that resolves with a boolean value indicating whether the client's API key is valid.

The promise rejects with an Error when an issue occurs. The error message usually includes some debug information, provided by the X-akismet-debug-help HTTP header, about what exactly was invalid about the call.

It can also reject with a custom error code and message (respectively provided by the X-akismet-alert-code and X-akismet-alert-msg headers). See Response Error Codes for more information.

Example

import console from "node:console";
import {Blog, Client} from "@cedx/akismet";

try {
  const blog = new Blog({url: "https://www.yourblog.com"});
  const client = new Client("123YourAPIKey", blog);

  const isValid = await client.verifyKey();
  console.log(isValid ? "The API key is valid." : "The API key is invalid.");
}
catch (error) {
    const message = error instanceof Error ? error.message : String(error);
    console.log(`An error occurred: ${message}`);
}

See the API reference for detailed information about the Client and Blog classes, and their properties and methods.