Download a CSV using api Extension

Hi,

I'm currently experimenting with the Bonita API extension. My goal is to generate a CSV file and send it to the user using the API extension.

Here's the code I have implemented so far:

try{
            def data = [
                ['Name', 'Age', 'City'],
                ['John Doe', 25, 'New York'],
                ['Jane Smith', 30, 'London'],
                ['Bob Johnson', 35, 'Paris']
            ]
 
            def csvContent = new StringWriter()
            def csvPrinter = new CSVPrinter(csvContent, CSVFormat.DEFAULT)
 
            csvPrinter.printRecord(data[0])
 
            for (int i = 1; i < data.size(); i++) {
                csvPrinter.printRecord(data[i])
            }
 
            csvPrinter.flush()
 
            def csvString = csvContent.toString()
 
            apiResponseBuilder.with {
                withResponse(csvString)
                withMediaType("application/csv")
                withAdditionalHeader("Content-Disposition", "attachment; filename=\"output.csv\"")
                withCharacterSet("ISO-8859-5")
                build()
            }

Currently, when I call the API, the file is downloaded but without the .csv extension. I would like to know if there is a better way to achieve this.

Thank you.