Problems with hitting your API using Node.js

Figured it out. Here’s the solution code:


const http = require('https');

const options = {
  hostname: 'community.myCompanyName.com',
  path: '/admin/plugins/explorer/queries/73/run',
  method: 'POST',
  headers: {
    accept: 'application/json',
    'Content-Type': 'multipart/form-data',
    'Api-Key': '<api_key>',
    'Api-Username': '<my_username>'
  }
};

var response = 1;

const req = http.request(options, (res) => {
  console.log(`statusCode: ${res.statusCode}`);
  response = res;

  res.on('data', (d) => {
    process.stdout.write(d);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.end();

var parsed_response = JSON.parse(response);
console.log(parsed_response);