Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/metabase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
},
};
8 changes: 8 additions & 0 deletions components/metabase/metabase.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion components/metabase/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/metabase",
"version": "0.1.1",
"version": "0.2.0",
"description": "Pipedream Metabase Components",
"main": "metabase.app.mjs",
"keywords": [
Expand Down