addObject failed

trying to get addobject method to work. ive installed the package and saved as a dependency however i keep getting an error saying im using the method wrong.

Here is the the code:

const client = algoliasearch('CZ18ALVO83', '24381f806e7326e7965c9547ba3dc28e');
const index = client.initIndex('your_index_name');

var request = require("request");

var beats = { method: 'GET',
  url: 'http://mygetroute/beats',
   { 'cache-control': 'no-cache',
     Connection: 'keep-alive',
     'accept-encoding': 'gzip, deflate',
     Host: 'host:8000',
     'Postman-Token': '6011ec13-c17f-4a02-bc31-db7b5a6c2b90,540b0a22-e77d-4db0-bea6-    20a1b24d202e',
 'Cache-Control': 'no-cache',
     Accept: '*/*',
     'User-Agent': 'PostmanRuntime/7.15.0' } };

index.addObjects(beats, function (error, response, body) {
  if (error) throw new Error(error);


and here is the error im getting

dev:~/environment/wuphf $ node index.js
    throw new Error(usage);

Error: Usage: index.addObjects(arrayOfObjects[, callback])
at Index.addObjects (/home/ec2-user/environment/wuphf/node_modules/algoliasearch/src/Index.js:64:11)
at Object.<anonymous> (/home/ec2-user/environment/wuphf/index.js:61:7)
at Module._compile (internal/modules/cjs/loader.js:774:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
at Module.load (internal/modules/cjs/loader.js:641:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
at internal/main/run_main_module.js:17:11

I’ve checked my endpoint on postman and it returns json in the proper format so i don’t know why it isnt working.

Hi @management,

Thanks for contacting Algolia.

The addObjects method takes as its two arguments: (1) an array; and (2) the callback.

It looks like you are using the variable beats as the first argument. At first glance, beats appears to be an {object} based on your code snippet. It may need to be wrapped in square brackets [beats] to be an array.

Can you try that?