Calling APIs on Connect from Node.js

Requirements

To call APIs hosted in Connect from Node.js, you’ll need:

  1. URL for the Connect Host
  2. Path for the API endpoint hosted on Connect
  3. API key (if your API requires authorization)

Node.js Example

You can use the https package in Node.js to call APIs from Node.js applications:

var https = require("https");

var connectApiHost = "connect.yourcompany.com"
var connectApiPath = "/rest-api/route"
var connectApiKey = "YfB5XBRB7slkkBSEi5qr93mWJvbpXQQy"

var options = {
  host: connectApiHost,
  path: connectApiPath,
  headers: {"Authorization": "Key " + connectApiKey},
  port: 443,
  method: "GET",
};

https.request(options, function(res) {
  console.log("STATUS: " + res.statusCode);
  console.log("HEADERS: " + JSON.stringify(res.headers));
  res.setEncoding("utf8");
  res.on("data", function (chunk) {
    console.log("BODY: " + chunk);
  });
}).end();

You can replace the values of connectApiHost, connectApiPath, and connectApiKey with the URL of the Connect server, the path to the API on Connect, and the API key from Connect.

Scope

The code examples assume that you are calling a published API in Connect that is:

  • Hosted on a secure server with TLS/SSL at an HTTPS endpoint
  • Using an API key to make an authorized call to an API
  • Making an HTTP GET request to the API

If your use case is different, then you can modify the example code accordingly.

Back to top