From b8ae9b50134957e5bb893649225567db1e941a3b Mon Sep 17 00:00:00 2001 From: Aryan Bagade <73382554+AryanBagade@users.noreply.github.com> Date: Thu, 20 Nov 2025 10:12:02 -0800 Subject: [PATCH 1/4] Metabase - Add export query with format action Add new action to export card queries with parameters in multiple formats (CSV, JSON, XLSX, API). This implements the /query/{export-format} endpoint which accepts parameters, resolving the critical blocker mentioned in issue #18970. Features: - Support for csv, json, xlsx, and api export formats - Parameters support for filtered queries - format_rows and pivot_results options - Follows existing Metabase component patterns Closes #18970 --- components/metabase/README.md | 3 +- .../export-query-with-format.mjs | 101 ++++++++++++++++++ components/metabase/metabase.app.mjs | 8 ++ components/metabase/package.json | 2 +- 4 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 components/metabase/actions/export-query-with-format/export-query-with-format.mjs diff --git a/components/metabase/README.md b/components/metabase/README.md index 01309df1c92f7..df5026849dcb7 100644 --- a/components/metabase/README.md +++ b/components/metabase/README.md @@ -7,7 +7,8 @@ The Metabase API opens a gateway to interact with Metabase programmatically, ena This Metabase integration provides the following actions: - **Run Query** - Execute a saved question/card and return the results -- **Get Dashboard** - Retrieve dashboard information and its cards +- **Export Query with Format** - Execute a saved question/card with parameters and export results in CSV, JSON, XLSX, or API format +- **Get Dashboard** - Retrieve dashboard information and its cards - **Create Dashboard** - Create a new dashboard in Metabase - **Get Database** - Retrieve database information and metadata diff --git a/components/metabase/actions/export-query-with-format/export-query-with-format.mjs b/components/metabase/actions/export-query-with-format/export-query-with-format.mjs new file mode 100644 index 0000000000000..c1816e35c48a3 --- /dev/null +++ b/components/metabase/actions/export-query-with-format/export-query-with-format.mjs @@ -0,0 +1,101 @@ +import app from "../../metabase.app.mjs"; + +export default { + key: "metabase-export-query-with-format", + name: "Export Query with Format", + description: "Execute a saved question/card with parameters and export results in the specified format (CSV, JSON, XLSX, or API). [See the documentation](https://www.metabase.com/docs/latest/api/card#post-apicardcard-idqueryexport-format).", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + type: "action", + props: { + app, + cardId: { + propDefinition: [ + app, + "cardId", + ], + }, + exportFormat: { + type: "string", + label: "Export Format", + description: "The format to export the query results in", + options: [ + { + label: "CSV", + value: "csv", + }, + { + label: "JSON", + value: "json", + }, + { + label: "XLSX", + value: "xlsx", + }, + { + label: "API", + value: "api", + }, + ], + }, + formatRows: { + type: "boolean", + label: "Format Rows", + description: "Whether to format rows for display", + optional: true, + default: false, + }, + pivotResults: { + type: "boolean", + label: "Pivot Results", + description: "Whether to pivot the results", + optional: true, + default: false, + }, + parameters: { + type: "string[]", + label: "Parameters", + description: "Query parameters as JSON objects. Each parameter should be a JSON string with the parameter properties. Example: `{\"type\": \"category\", \"target\": [\"variable\", [\"template-tag\", \"parameter_name\"]], \"value\": \"your_value\"}`", + optional: true, + }, + }, + async run({ $ }) { + const { + app, + cardId, + exportFormat, + formatRows, + pivotResults, + parameters, + } = this; + + // Parse parameters from JSON strings to objects + const parsedParameters = parameters?.map((param) => { + if (typeof param === "string") { + return JSON.parse(param); + } + return param; + }); + + const response = await app.exportCardQuery({ + $, + cardId, + exportFormat, + data: { + format_rows: formatRows, + pivot_results: pivotResults, + ...(parsedParameters && parsedParameters.length > 0 && { + parameters: parsedParameters, + }), + }, + }); + + $.export("$summary", `Successfully exported query results as ${exportFormat.toUpperCase()}`); + + return response; + }, +}; diff --git a/components/metabase/metabase.app.mjs b/components/metabase/metabase.app.mjs index 77bdeae72509b..e117f3f5cdbfb 100644 --- a/components/metabase/metabase.app.mjs +++ b/components/metabase/metabase.app.mjs @@ -140,6 +140,14 @@ export default { ...args, }); }, + exportCardQuery({ + cardId, exportFormat, ...args + } = {}) { + return this.post({ + path: `/card/${cardId}/query/${exportFormat}`, + ...args, + }); + }, createDashboard(args = {}) { return this.post({ path: "/dashboard", diff --git a/components/metabase/package.json b/components/metabase/package.json index 36c3cf08f99ae..507525bc07170 100644 --- a/components/metabase/package.json +++ b/components/metabase/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/metabase", - "version": "0.1.1", + "version": "0.2.0", "description": "Pipedream Metabase Components", "main": "metabase.app.mjs", "keywords": [ From 2b532423a1f48fbf3613b52dd9a4511248d5a865 Mon Sep 17 00:00:00 2001 From: Aryan Bagade <73382554+AryanBagade@users.noreply.github.com> Date: Thu, 20 Nov 2025 10:27:37 -0800 Subject: [PATCH 2/4] Add error handling for JSON.parse in parameters Address CodeRabbit feedback: wrap JSON.parse in try-catch to provide clear error messages when users provide invalid JSON strings. --- .../export-query-with-format/export-query-with-format.mjs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/metabase/actions/export-query-with-format/export-query-with-format.mjs b/components/metabase/actions/export-query-with-format/export-query-with-format.mjs index c1816e35c48a3..f899e9e85e447 100644 --- a/components/metabase/actions/export-query-with-format/export-query-with-format.mjs +++ b/components/metabase/actions/export-query-with-format/export-query-with-format.mjs @@ -74,9 +74,13 @@ export default { } = this; // Parse parameters from JSON strings to objects - const parsedParameters = parameters?.map((param) => { + const parsedParameters = parameters?.map((param, index) => { if (typeof param === "string") { - return JSON.parse(param); + try { + return JSON.parse(param); + } catch (error) { + throw new Error(`Invalid JSON in parameter at index ${index}: ${error.message}`); + } } return param; }); From 45ee533cf3112ba2f374f08f5494369ee2da256e Mon Sep 17 00:00:00 2001 From: Aryan Bagade <73382554+AryanBagade@users.noreply.github.com> Date: Thu, 20 Nov 2025 11:58:07 -0800 Subject: [PATCH 3/4] Bump patch version of dependent Metabase actions --- .../metabase/actions/create-dashboard/create-dashboard.mjs | 2 +- components/metabase/actions/get-dashboard/get-dashboard.mjs | 2 +- components/metabase/actions/get-database/get-database.mjs | 2 +- components/metabase/actions/run-query/run-query.mjs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/metabase/actions/create-dashboard/create-dashboard.mjs b/components/metabase/actions/create-dashboard/create-dashboard.mjs index fb08d7eecd259..632ad3e23c93c 100644 --- a/components/metabase/actions/create-dashboard/create-dashboard.mjs +++ b/components/metabase/actions/create-dashboard/create-dashboard.mjs @@ -5,7 +5,7 @@ export default { key: "metabase-create-dashboard", name: "Create Dashboard", description: "Create a new Dashboard. [See the documentation](https://www.metabase.com/docs/latest/api#tag/apidashboard/post/api/dashboard/).", - version: "0.0.3", + version: "0.0.4", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/metabase/actions/get-dashboard/get-dashboard.mjs b/components/metabase/actions/get-dashboard/get-dashboard.mjs index c05f4c4496d52..78425c7823c30 100644 --- a/components/metabase/actions/get-dashboard/get-dashboard.mjs +++ b/components/metabase/actions/get-dashboard/get-dashboard.mjs @@ -4,7 +4,7 @@ export default { key: "metabase-get-dashboard", name: "Get Dashboard", description: "Retrieve dashboard information and its cards. [See the documentation](https://www.metabase.com/docs/latest/api#tag/apidashboard/get/api/dashboard/{id}).", - version: "0.0.3", + version: "0.0.4", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/metabase/actions/get-database/get-database.mjs b/components/metabase/actions/get-database/get-database.mjs index f37f11af5ab95..ceb75378f81e6 100644 --- a/components/metabase/actions/get-database/get-database.mjs +++ b/components/metabase/actions/get-database/get-database.mjs @@ -4,7 +4,7 @@ export default { key: "metabase-get-database", name: "Get Database", description: "Retrieve database information. [See the documentation](https://www.metabase.com/docs/latest/api#tag/apidatabase/get/api/database/{id}).", - version: "0.0.3", + version: "0.0.4", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/metabase/actions/run-query/run-query.mjs b/components/metabase/actions/run-query/run-query.mjs index 2ba4e96efdf17..e40619aa68c74 100644 --- a/components/metabase/actions/run-query/run-query.mjs +++ b/components/metabase/actions/run-query/run-query.mjs @@ -4,7 +4,7 @@ export default { key: "metabase-run-query", name: "Run Query", description: "Execute a saved question/card and return the results. [See the documentation](https://www.metabase.com/docs/latest/api#tag/apicard/post/api/card/{card-id}/query).", - version: "0.0.3", + version: "0.0.4", annotations: { destructiveHint: false, openWorldHint: true, From c38f1bb490cc21218212f4fb62509d8d91d6eb9e Mon Sep 17 00:00:00 2001 From: Leo Vu Date: Fri, 21 Nov 2025 14:10:32 +0700 Subject: [PATCH 4/4] Improve suggestion --- .../export-query-with-format/export-query-with-format.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/metabase/actions/export-query-with-format/export-query-with-format.mjs b/components/metabase/actions/export-query-with-format/export-query-with-format.mjs index f899e9e85e447..c2da255c8811e 100644 --- a/components/metabase/actions/export-query-with-format/export-query-with-format.mjs +++ b/components/metabase/actions/export-query-with-format/export-query-with-format.mjs @@ -3,7 +3,7 @@ import app from "../../metabase.app.mjs"; export default { key: "metabase-export-query-with-format", name: "Export Query with Format", - description: "Execute a saved question/card with parameters and export results in the specified format (CSV, JSON, XLSX, or API). [See the documentation](https://www.metabase.com/docs/latest/api/card#post-apicardcard-idqueryexport-format).", + description: "Execute a saved question/card with parameters and export results in the specified format (CSV, JSON, XLSX, or API). [See the documentation](https://www.metabase.com/docs/latest/api#tag/apicard/post/api/card/%7Bcard-id%7D/query).", version: "0.0.1", annotations: { destructiveHint: false,