CSV Download & filtered queries

I am trying to learn how to use the export to csv and then download the file.

It works fine if I want to download the whole query in the API. I then call the API from a button on a page.

Then if I put a condition into the database I start to get problems.

It works fine if I hard code the condition (eg contact_name contains “test”) but as soon as I make the condition based on the $GET_filter I get a error 500 when I click the download button.

I have tried toggling the output switches but that makes no difference.

Can anybody offer some help?

Thanks,

Try to approach this is a diffrent way… dont put the download in the same SC file.. as the create file…

Query the data….
Check if data returns value
If data is returned then export to csv file
Check if the file has been created and in the folder

Then on the SC for the above… On-Success.. (in a flow) call a diffrent SC file for the download…
Create the download step… then add a “wait” step to delete the file from the folder you just downloaded…

so 2 SC connect files.

  1. That queries…and creates the file.
  2. That (on success from the above) will download the file and deletes it.

Did you remember to bind your filter variable in your input field in your server connect action, forgetting to do that would result in a 500 error as $_GET.filter would be undefined.

Thanks for that. I have followed your advice as I think that it is sound but it was not the core of the issue. I had to change my condition to this:

and then created a separate download API which I then call from a button via a routing and browser element.

So clicking the button ran the CSV API and then routed to the file for download.

Thanks for taking the time to respond.

1 Like

Hi Brian,

Thanks again for responding.

I had done that but it was still not send a value to the CSV exporter. I have to change my conditions in the query to this

I had to create a separate API for the download and then do this:

On button click:

On server action success: