Generate CSV Pipe
Tadabase Support is unavailable for this pipe. View the documentation below for guidance.
The Generate CSV pipe allows your users to export CSVs directly from your live Tadabase app. This Pipe allows your users to export a limited number of records, versus allowing your users to have full access to your database with the Tadabase 'Export' Data Component.
This pipe is partially-configurable and the Parameters, Request, Response, and Headers tabs can all be easily adjusted according to your specifications. For example, if it suits your app's requirements, you can replace dynamic parameters in the Request tab with hard-coded data. For more information on customizing pipes, see the article on Adding Custom Pipes.
Please Note: If you are hard-coding your parameters, remember to set the parameters' required option to 'off' in the Parameters tab (if you won't be using them). Otherwise, you will get an error, and the pipe will not be triggered.
Install the Generate CSV Pipe
1. Navigate to the Pipes section in your Tadabase app and click 'Install Pipe'.
2. Type 'Generate CSV' into the search bar and click on the pipe to install.
3. Click the 'Install' button.
4. A pop-up window will appear prompting you to:
A. Select your Tadabase API Key from the dropdown menu.*
Learn how to generate a new Tadabase API Key: https://developer.tadabase.io/#intro
*required
B. Select the Table and Field where you would like to save the generated CSV file.*
*required
The field you select must be a file/attachments field.
C. Enter the Record ID of the specific record where you would like to save the generated CSV file (optional). Then, click Install to install the pipe.
If you want to always save a file back to the same record, fill out this parameter with a default value, otherwise you'll be able to dynamically pass the current record ID through the page builder functions.
Note: You can save the Record ID via a Table Rule. See the documentation for more details.
This field is optional. Default Record ID value to be used if not otherwise set.
API Calls
Additionally, you can adjust any of the following operations in the API Call:
Create a CSV and Save it Back to Tadabase
Parameters
- Max* - Enter the maximum number of records that can be exported.
- Filter Field - Select the field in your table that you would like to filter the records by.
- Filter Value - Enter the value that you would like to filter the above field by.
- Sort Field - Select the field that you would like the records to be sorted by.
- Sort By - Options: asc or desc
- CSV Column 1 Field - Select the field for the first column in the CSV.
- CSV Column 1 Heading - Specify the heading for the first column in the CSV.
- CSV Column 2 Field - Select the field for the second column in the CSV.
- CSV Column 2 Heading - Specify the heading for the second column in the CSV.
- CSV Column 3 Field - Select the field for the third column in the CSV.
- CSV Column 3 Heading - Specify the heading for the third column in the CSV.
-
Save to Record ID* - Enter the Record ID of the specific record where you would like to save the generated CSV file if you did not enter it on install.
*required
Response
- CSV Status
- Total Records
- Message
Let us examine the example below.
1. The maximum number of records that can be exported is 50 records, as the 'Max' parameter is set to 50.
2 & 3. We chose to filter the records by the Status (in the Sample Data Table) set to 'Lead'. Only records that the status is set to 'Lead' will be exported in the CSV.
4 & 5. We chose to sort the records by Customer (in the Sample Data Table) in ascending order.
6 & 7. The first column to be displayed in the CSV will be the Email field from the Sample Data Table. The heading of this column will be 'Email'.
8 & 9. The first column to be displayed in the CSV will be the Contact Date field from the Sample Data Table. The heading of this column will be 'Contact Date'.
10 & 11. The first column to be displayed in the CSV will be the Customer field from the Sample Data Table. The heading of this column will be 'Customer'.
After running this API Call in the 'Test' tab, navigate to the Data Builder to the Table and Field (which were selected on Install) where the CSV file will be saved and ready to download.
See the CSV from the example above.
We can predict that this CSV will contain a max of 50 records, and will display Customers in ascending order whose statuses are set to 'Lead'. The first column will be called 'Email' and display the 'Email' field, the second column will be called 'Contact Date' and display the 'Contact Date' field, and the third column will be called 'Customer' and display the 'Customer' field.
Filters
You can add filters in the request tab by adding another 'filter' parameter in the request. In the code below, we added another 'filter' parameter called 'Filter Field 2', filtering with a value called 'Filter Value 2'. These parameters must be added in the Parameters Tab as well.
"filters":[
{"field_id" : "{Filter Field}", "value" : "{Filter Value}"},
{"field_id" : "{Filter Field 2}", "value" : "{Filter Value 2}"}
],
First, find the slug of the field in your table that you would like to filter the records by. Next, enter the value that you would like to filter the above field by. (See below for more information on how to find the field slug.) The example below shows the new, added filter that filters the records to only display fields with the Contact Date (field_34) of 9/25/2019
You can also change the values in the request to static values, just remember to set the parameters' required option to 'off' in the Parameters tab if you won't be using them. Otherwise, you will get an error, and the pipe will not be triggered.
You can also remove filters by deleting the 'filter' parameters in the 'Request' tab.
Be sure to edit the 'Parameters' Tab accordingly. If you delete filters in the 'Request', delete the filters in the 'Parameters' Tab as well.
Column Amount
You can add/remove columns in the request tab.
You can add additional columns in the 'Request' Tab to be generated in the CSV file.
Add a comma after the line of code shown below, and copy and paste that line of code on the next line. Exchange the number '3' for '4' to make a 4th column. You can keep adding lines of code this way, always making sure to add a comma after the previous line and to exchange the number in the pasted line with the number of the column that you are adding.
In the example below, the generated CSV file will have 5 columns.
"csv_columns": [
{"column_heading": "{CSV Column 1 Heading}", "id": "{CSV Column 1 Field}"},
{"column_heading" : "{CSV Column 2 Heading}", "id" : "{CSV Column 2 Field}"},
{"column_heading" :"{CSV Column 3 Heading}", "id": "{CSV Column 3 Field}"},
{"column_heading" :"{CSV Column 4 Heading}", "id": "{CSV Column 4 Field}"},
{"column_heading" :"{CSV Column 5 Heading}", "id": "{CSV Column 5 Field}"}
],
Be sure to edit the 'Parameters' Tab accordingly. If you add columns in the 'Request', add the columns in the 'Parameters' Tab.
First, find the Field Slug of the field you are adding as the next column.
Finding the Field Slug
To find the Field Slug, navigate to the Data Builder, click on the table that the field is in, click on the 'Fields' Tab, and check off 'Show Field Slug'. Find the Field Slug for the field that you are adding as a column to the CSV.
Next, add the slug in the 'Parameters' tab and specify the heading name for the column in the CSV.
You can also remove columns by deleting the last line of code in that section. In the example below, the generated CSV file will have 2 columns.
"csv_columns": [
{"column_heading": "{CSV Column 1 Heading}", "id": "{CSV Column 1 Field}"},
{"column_heading" : "{CSV Column 2 Heading}", "id" : "{CSV Column 2 Field}"}
],
Be sure to edit the 'Parameters' Tab accordingly. If you delete columns in the 'Request', delete the columns in the 'Parameters' Tab as well.
We'd love to hear your feedback.