ApiError: body must contain an object near line:1 column:45

I’m trying to create a Github action to pass a json file to an index, but for some reason this error is shown:

name: 'ApiError',
message: 'body must contain an object near line:1 column:45',
status: 400,
  transporterStackTrace: [
    {
      request: [Object],
      response: [Object],
      host: [Object],
      triesLeft: 3
    }
  ]

Edit: on GUI, with the same data (./data/example.json), I receive a
body of batch should be an object and not an array near line:1 column:4436 error.

What I’m doing wrong?

You can see the data and the response here: https://github.com/AdrianoCahete/algolia-update-action/runs/700624340?check_suite_focus=true#step:3:10

The data raw: https://github.com/AdrianoCahete/algolia-update-action/blob/master/data/example.json
The index.js/code: https://github.com/AdrianoCahete/algolia-update-action/blob/master/index.js

I’m following this documentation.

Hi there,

The last record you are sending is wrapped into an additional array:

Avoiding that will fix the issue.

I removed but didn’t fix it. The error is the same.

Could you share again the new payload and the error?

Sure: https://github.com/AdrianoCahete/algolia-update-action/runs/707519251?check_suite_focus=true#step:3:12

Hi there,

It seems like the payload you’re sending in the last run you’ve posted still contains the array around the last object. Could you perhaps force a run with your newly updated data file, and post the result here if you still get the error?

Thank you in advance!

I’m trying to find if it’s a problem with my code and removed the stringfy on the last commit (using the fs to open the file directly), but the error is the same: https://github.com/AdrianoCahete/algolia-update-action/runs/718928028?check_suite_focus=true#step:3:266

Hi Adriano,

I can see in your code that you’re transforming the output of your file reader to a JSON object but then use the direct output of the filereader here

obj = JSON.parse(data);
...
Promise.resolve(index.replaceAllObjects(data,  ...));

This is where your issue comes from. If you use your obj variable it will work.

Please tell us if it solved your issue.