Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
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#tag/apicard/post/api/card/%7Bcard-id%7D/query).",
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, index) => {
if (typeof param === "string") {
try {
return JSON.parse(param);
} catch (error) {
throw new Error(`Invalid JSON in parameter at index ${index}: ${error.message}`);
}
}
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;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/metabase/actions/get-database/get-database.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/metabase/actions/run-query/run-query.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
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
Loading