Skip to content
Ozgur Ozcitak edited this page May 3, 2019 · 14 revisions

Creating the Client

    var akismet = require('akismet').client(options);

where options must include the blog url and Akismet API key. Rest of the options are optional and default values are as shown below:

Name Description Default Value
blog Blog URL <none>
apiKey Akismet API key <none>
host Akismet API server rest.akismet.com
endPoint API endpoint apiKey.rest.akismet.com
port Server port 80
userAgent User agent string passed to the API server Generic Node.js/1.0.0 | Akismet/3.1.7
charSet Text encoding utf-8

For example:

    var akismet = require('akismet').client({ 
      blog: 'http://my.blog.com', 
      apiKey: 'myakismetapikey123' 
    });

Verifying the API Key

    akismet.verifyKey(callback);

where callback takes two arguments: err and verified. verified will be true if the API key was successfully verified.

Name Description
callback The function to be called when the API returns. The function signature should be callback = function(err, verified) {} where err is an error string or null and verified is a boolean value.

For example:

    akismet.verifyKey(function(err, verified) {
      if (verified) 
        util.log('API key successfully verified.');
      else 
        util.log('Unable to verify API key.');
    });

Checking for Spam

    akismet.checkComment(args, callback);

where args contain query string parameters as key/value pairs. callback takes two arguments: err and spam. spam will be true if the Akismet API identifies the comment as spam.

Name Description
args key/value pairs of query string parameters as a JS object
callback The function to be called when the API returns. The function signature should be callback = function(err, spam) {} where err is an error string or null and spam is a boolean value.

For example:

    akismet.checkComment({ 
        user_ip: '1.1.1.1', 
        permalink: 'http://www.my.blog.com/my-post',
        comment_author: 'spammer',
        comment_content: 'spamming your comments'
      }, function(err, spam) {
        if(spam)
          util.log('Spam caught.');
        else
          util.log('Not spam');
    });

Sending Feedback to Akismet

    akismet.submitSpam(args, callback);
    akismet.submitHam(args, callback);

If the Akismet API returns false positives or false negatives you can send feedback to the API with these functions. Their usage is the same as checkComment. args contain query string parameters as key/value pairs. callback takes an err argument.

Name Description
args key/value pairs of query string parameters as a JS object
callback The function to be called when the API returns. The function signature should be callback = function(err) {} where err is an error string or null.

For example:

    akismet.submitSpam({ 
        user_ip: '1.1.1.1', 
        permalink: 'http://www.my.blog.com/my-post',
        comment_author: 'spammer',
        comment_content: 'spamming your comments'
      }, function(err) {
        util.log('Spam reported to Akismet.');
    });
Clone this wiki locally