Parse a csv file and send an API request for each row

I want to select a CSV file (up to 100 rows) from a file input selector and then make a POST to my server for each row in the file using the data in the row as parameters in the Post body.

Do I need a script as the Event Handler in my file input, which includes a loop per row to call the API? A close example would be great!

Thanks!

Ian

That's the way to go @ianhendry99! There are a couple of examples in our docs that both use additionalScope to do so. Let me know if they help or raise any further questions :slightly_smiling_face:

Thanks @Kabirdas , I understand now how to do it but I have a basic issue at the start of my script, I notice the fileInput returns an array of arrays (i.e. one for each file). II am only importing one file and can successfully display the contents in a table using this expression: {{fileInput1.parsedValue['0']}}

But when I try to assign a const or var to the same expression to use in my for loop (see line 1 below), I get an error:
Screenshot 2023-01-25 124628

const deviceInputArray = {{fileInput1.parsedValue['0']}}
for (let thisrow of deviceInputArray) {
....

do you know what the issue is?

Hmm... would you mind posting the full script @ianhendry99? It might also be helpful if you can take a screenshot of fileInput1.parsedValue[0] expanded to show its structure from the State tab of either your left panel or the debug console.

The error indicates there's an issue with an array being declared somewhere (docs) but I don't see immediately where that would be.

I just solved it.
const deviceInputArray = fileInput1.parsedValue['0']

I assume you don't need the curly brackets as you are calling the script from inside the fileInput1 object.

Thanks for your time!

1 Like