addObject -> 'body must contain an object near line ..."

Using addObject to add records to first index. Getting exception thrown 'body must contain an object near line: 1 column:171789". Using PHP API addObject method.

From debugger, copied json that was sent to addObject, and created file. Then, uploaded that file via the Dashboard. Loaded fine.

Looking for guidance on what’s going wrong with API call to upload records.

    $this->client = SearchClient::create(
    $index = $this->client->initIndex('Events');
    $records = $this->buildIndexEvent($memberEvent, $event);
    $jsonRecords = json_encode($records);
    $index->saveObject($jsonRecords, ['autoGenerateObjectIDIfNotExist' => true]);

Hi @icefield, that’s curious indeed. Would you mind sending the sample JSON that is causing this error to so that so we can try to reproduce and investigate?

Thanks in advance!

Hi Maria,

I had a few things incorrect, which I’ve resolved. For any one that may stumble across this thread in the future, here is what I was doing wrong:

  1. I originally had my record structure way too large, and was attempting to load a single (large) record at a time using ‘addObject’. That failed with an exception (unrelated to the size of the record, but when I tried to upload the data via the Dashboard, I received a useful error).

  2. I restructured the data into many smaller records, but neglected to change ‘addObject’ to ‘addObjects’. Discovered that after my walk this afternoon to clear my head.

  3. Then, I thought I had seen an example where the data sent to ‘addObjects’ had to be json_encode’d prior calling that method. Can’t find that example now. In any case, I now pass an array of records (not json_encode’d) to ‘addObjects’, and all is well.

A newby here with this platform, but making some progress now.


1 Like

Glad you were able to resolve on your own and many thanks for posting what you found here!