benwinding / react-admin-import-csv

A csv file import button for react-admin

Home Page:https://benwinding.github.io/react-admin-import-csv

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The response to 'getMany' must be like { data : [...] }

koaladlt opened this issue · comments

Hi there!

I'm having this issue, I'm not sure if I'm missing something, but here I go:

When I upload a CSV file, it looks like is making a get request filtering some data, and I'm dealing with this error:

The response to 'getMany' must be like { data : [...] }, but the received data is not an array. The dataProvider is probably wrong for 'getMany'

Screen Shot 2021-09-20 at 18 53 05

This is happening even though I'm receiving the data in the correct way:

Screen Shot 2021-09-20 at 18 55 32

Here in Postman:

Screen Shot 2021-09-20 at 18 58 00

I hope someone can help me out with this, thanks a lot!

Hi @koaladlt,

So before it executes the import, this library checks if the csv rows have already been imported (using getMany on your dataprovider).

That error seems to be related to a problem with your data-provider's getMany method, and is an error thrown by the react-admin framework, see here for details (https://marmelab.com/react-admin/DataProviders.html#request-format), not this library.

Also, the images you provided are ok, but it's much better to include the raw text from the error message, that way other people can find this issue in the future.

If you provide more context and code, I can help solve your problem, a small project reproducing the error would be perfect.

Cheers,
Ben

Hi @benwinding, thank you for your response.

I think I know the problem, I'm not pretty sure but it looks like I need to retrieve the data in the exact format that React Admin wants it.

My API was retrieving the data in this way:
{data: [{id:1, productName: ...}], total:3}

And I think that I need to remove the total key from the initial object:
{data:[{id:1, productName: ...]}

Thanks a lot and sorry for the inconvenience.

PS: I'm editing the original post with the raw text from the error message.

Glad to hear you got it working!