Access OpenCalais from Node.js

To access OpenCalais for entity recognition, you’ll need an API key, and some text to check:

let inputData = `
Professor Sir Richard Evans FBA is Provost of Gresham College and 
the President of Wolfson College, Cambridge. He was Regius Professor 
of History at the University of Cambridge from 2008 until his retirement 
in September 2014. He is a world-renowned historian and academic, with 
many of his books now acknowledged as seminal works in the field of 
modern history.`;
let token = 'insert token here';

This requires the Node HTTPs library as a dependency (there are a couple unmaintained wrappers around OpenCalais for Node, but I found none of them work).

let https = require('https');

Once you do this, you just need to drop in all the parameters you need, and run a typical Node HTTP request:

const options = {
  host: "",
  port: "443",
  path: "/permid/calais",
  method: "POST",
  headers: {
    "Content-Type": "text/raw",
    "OutputFormat": "application/json",
    "X-AG-Access-Token": token,
    "Content-Length": new Buffer(inputData).length
const req = https.request(options, 
  (res) => {
    let resultData = "";
    res.on("data", (d) => {
      resultData += d;
    res.on("end", () => {

Once you do this, you’ll get a ton of detail (on first glance, this seems much more detailed than AlchemyAPI):

  "": {
    "_typeGroup": "relations",
    "_type": "Trial",
    "forenduserdisplay": "false",
    "_typeReference": "",
    "person": "",
    "instances": [
        "detection": "[About Hitler: The Holocaust, History, and the ]David Irving Trial[ (2002), In Defe
nce of History (1997), Rituals of]",
        "prefix": "About Hitler: The Holocaust, History, and the ",
        "exact": "David Irving Trial",
        "suffix": " (2002), In Defence of History (1997), Rituals of",
        "offset": 1742,
        "length": 18