[object Object] error sending data to Algolia

This topic was automatically generated from Slack. You can find the original thread here.

Jansen Gunderson : Hello, I’m developing a Google Drive workflow that adds new objects to an Algolia index. I’m receiving an error on steps.add_objects_to_index:

Dylan Sather (Pipedream) : would you mind expanding the code section of the step, and replacing the existing code with this?

const algoliasearch = require("algoliasearch");

try {
  const client = algoliasearch(auths.algolia.application_id, auths.algolia.api_key);
  const index = client.initIndex(params.index);

  this.objectIds = await index.saveObjects(params.objects, {
    autoGenerateObjectIDIfNotExist: params.autoGenerateObjectIDIfNotExist || true
  })
} catch (err) {
  throw new Error(JSON.stringify(err))
}

Dylan Sather (Pipedream) : then try running the step one more time, and let me know if you see more details on the error

Jansen Gunderson : Thank you Dylan. The error returned:
Error{"name":"ApiError","message":"body of batch should be an object and not an array near line:1 column:43","status":400,

Jansen Gunderson : I refactored my code to send an object instead of an array to Algolia and all is good.

Dylan Sather (Pipedream) : Great, glad that worked