Skip to main content

How to Export Memberstack Data Table Records

Memberstack Team
Memberstack Team
  • Updated

If you need to export Data Table records for backups, analytics, or migrations, you can export the records as a CSV file directly via Memberstack dashboard or retrieve the records programmatically and convert the returned data to CSV.

Export Data Table Records via Dashboard

You can export Data Table records as a CSV file via Memberstack dashboard.

1. Go to your Memberstack dashboard and click Members > Data Tables on the side menu.

2. Open the relevant Data table that you want to export.

3. Click on the vertical ellipsis icon (⋮) at the top-right corner and click "Export CSV"

4. Select the columns that you want to be included in the export file and click on the "Export CSV" button.

Memberstack will generate the export and email a secure CSV download link directly to your account email address. 

Export Data Table Records Programmatically

You can also retrieve Data Table records using the Memberstack developer packages and then convert the returned data to CSV.

Option 1: Backend with the Memberstack Admin SDK (@memberstack/admin)

Use memberstack.dataTables.queryRecords() to retrieve records. To export an entire table, you can use the findMany query wrapper and request records in pages of up to 100 using cursor-based pagination sorted by ascending  internalOrder: 

const allRecords = [];
let afterCursor;
let hasMore = true;
while (hasMore) {
const { data } = await memberstack.dataTables.queryRecords({
table: "your_table_slug",
query: {
findMany: {
orderBy: { internalOrder: "asc" },
take: 100,
...(afterCursor ? { after: afterCursor } : {})
}
}
});
allRecords.push(...data.records);
hasMore = data.pagination?.hasMore || false;
afterCursor = data.pagination?.endCursor;
}
console.log("Total records retrieved:", allRecords.length);

For large tables, retrieve the records in pages and continue requesting records until all pages have been retrieved.

Option 2: Frontend with the Memberstack DOM Package (@memberstack/dom)

If fetching records from client-side code, use memberstack.queryDataRecords(). Note that the DOM SDK automatically wraps your query in findMany, so pass the query object directly: 

const { data } = await memberstack.queryDataRecords({
table: "your_table_slug",
query: {
orderBy: { internalOrder: "asc" },
take: 100
}
});
console.log("Records:", data.records);
if (data.pagination?.hasMore) {
const nextPage = await memberstack.queryDataRecords({
table: "your_table_slug",
query: {
orderBy: { internalOrder: "asc" },
take: 100,
after: String(data.pagination.endCursor)
}
});
}

Converting JSON to CSV:
Once your records are retrieved in JSON format, convert the array of record objects into CSV format using a standard library which converts JSON to CSV, or import the JSON file directly into tools like Google Sheets or Excel.

Keeping an Ongoing Copy of Your Data:
If you need continuous access to your table data rather than a one-time export, consider using Memberstack API or no-code integrations like Make or Zapier. You can regularly fetch and push the records into Google Sheets or Airtable.

Was this article helpful?

Didn’t find your answer?

Get an instant answer from Rey, or reach a human. Either way, we’re happy to help.

Comments

No comments yet. Start the conversation below.

Please sign in to leave a comment.