Extract an array from an API call and export that as a CSV file

I have an API return that I would like to export as a CSV file. The trick I am running into is that I only want to grab the area inside the content array and then return that data. What steps can I take to get that working? Is there a specific plugin that can help there?

    "totalPages": 3,
    "totalElements": 60,
    "number": 0,
    "size": 20,
    "content": [
            "id": 1,
            "Name": "Name One",
            "state": "WY"
            "id": 2,
            "Name": "Name Two",
            "state": "WY"

Do you want to download the csv file from the browser or do everything behind the scenes from the user? I asked ChatGPT how to create a CSV file and the following Javascript will work. You will just need to use the free Toolbox plugin to get the action Run Javascript and then you can paste the following code after the API call:

This first section is the only part that you will have to insert dynamic data.

// Example text data
const textData = "Result of Step1's content:format as text";

Then in the format as text box make use \n as the delimeter and for each item say “This content’s id, This content’s Name, This content’s state”

// Convert text data into an array
const dataArray = textData.trim().split('\n').map(row => row.split(','));

// Define headers for CSV file
const headers = ['id', 'Name', 'state'];

// Function to convert array to CSV string
function arrayToCSV(data) {
  const csvRows = [];
  data.forEach(row => {
  return csvRows.join('\n');

// Convert array to CSV string
const csvData = arrayToCSV(dataArray);

// Create Blob object for CSV data
const blob = new Blob([csvData], { type: 'text/csv' });

// Create download link for CSV file
const downloadLink = document.createElement('a');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'data.csv';

1 Like

That is pretty cool to see ChatGPT can code for Bubble!

Custom coding the solution may be useful as I want to eventually modify which columns get exported based on which ones are shown and hidden.

Thanks for taking a look at this.

This topic was automatically closed after 70 days. New replies are no longer allowed.