Edit: Currently using the array fields directly, so low priority issue
Hi,
I’m using API Action to download a CSV file from a remote API. It’s downloaded as a text string, how do I use the Import CSV step with a CSV that isn’t present on the file-system? Or how do I save the file to filesystem so I can then use Import CSV? I think Wappler doesn’t support this yet?
Thanks for any advice! This is NodeJS.
Edit: Previously I’ve attempted to split the string at \n to get an array of lines, and then at “,” to get an array of the individual fields. Is there a way I can create an object with the fields inside? I’ve attempted to use “Set Value”, but I couldn’t get to the point of building the object (typing a JSON object in the data expression threw a syntax error or something), see screenshot below. I’ve ended up deleting those steps mistakenly
The goal of creating the object is just so I have some sort of type-safety, instead of going around with array[3] around the script
I have a project where I download a csv from some url. This csv content needs to be matched with the database content and modify changed data / add new data. I’m not sure if this is similar to your situation.
If it is I can suggest a workaround, because I couldn’t figure out how to do this with the Wappler UI. What I have done is I created a Python script using Requests to get the csv file (or connect to your API) and I use Pandas to extract only the information I need from the CSV.
Then using Requests again I send the data over to my Wappler api endpoint that does the queries on the database.
Does this make sense to you? I’d be happy to share some code if this direction feels like something you want to go for.
I can then access each CSV field by fields[0], fields[1], etc..
I'm sure your Python script offers better assurances in regards to type safety, as my current solution is more prone to mistakes handling data. For now, I think I'll let it be this way, but thank you very much for the offer of code sharing!
How do you access the fields after the last Set value, please? When you want to use each csv column for a specific column in Db insert. I can’t figure it out…I need to parse csv and work with all the rows and columns from it - to filter, db insert, etc.