Skip to content

Commit 6e084aa

Browse files
committed
[Components] Metabase - new components
1 parent 163ad45 commit 6e084aa

File tree

13 files changed

+646
-28
lines changed

13 files changed

+646
-28
lines changed

components/metabase/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

components/metabase/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,24 @@
22

33
The Metabase API opens a gateway to interact with Metabase programmatically, enabling you to automate reporting, dashboards, and data analysis operations. With Pipedream, you can harness this API to trigger workflows, manipulate data, and integrate with various other apps to create a seamless data ecosystem. Think of syncing Metabase insights with other tools, automating report generation, or reacting to events within your Metabase instance in real-time.
44

5+
# Available Actions
6+
7+
This Metabase integration provides the following actions:
8+
9+
- **Run Query** - Execute a saved question/card and return the results
10+
- **Create Card** - Create a new question/card in Metabase
11+
- **Get Dashboard** - Retrieve dashboard information and its cards
12+
- **Create Dashboard** - Create a new dashboard in Metabase
13+
- **Get Database** - Retrieve database information and metadata
14+
515
# Example Use Cases
616

717
- **Automated Reporting**: Use Pipedream to set up scheduled triggers that fetch reports from Metabase and send them via email or Slack. This workflow can help teams stay updated with the latest insights without manual intervention.
818

919
- **Dashboard Sync**: Create a workflow that listens for updates in a specific Metabase dashboard and synchronizes those changes with a Google Sheets document. This allows for easy sharing and collaboration on data insights with stakeholders who prefer working in spreadsheets.
1020

1121
- **Alerting on Metrics**: Set up a Pipedream workflow that monitors specific metrics within Metabase. If certain thresholds are crossed, actions can be taken automatically, like sending alerts through SMS using Twilio or creating a task in project management tools like Trello.
22+
23+
- **Data Pipeline Automation**: Automatically create new cards and dashboards when new data sources are added, or when specific business events occur.
24+
25+
- **Cross-Platform Integration**: Sync Metabase insights with CRM systems, marketing tools, or business intelligence platforms to create a unified view of your data across all systems.
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
import app from "../../metabase.app.mjs";
2+
import { VISUALIZATION_TYPES } from "../../common/constants.mjs";
3+
import utils from "../../common/utils.mjs";
4+
5+
export default {
6+
key: "metabase-create-card",
7+
name: "Create Card",
8+
description: "Create a new `Card`. Card `type` can be `question`, `metric`, or `model`. [See the documentation](https://www.metabase.com/docs/latest/api#tag/apicard/post/api/card/).",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
app,
13+
visualizationSettings: {
14+
type: "object",
15+
label: "Visualization Settings",
16+
description: "Visualization settings configuration",
17+
},
18+
dashboardTabId: {
19+
type: "integer",
20+
label: "Dashboard Tab ID",
21+
description: "Dashboard tab identifier (must be greater than zero)",
22+
min: 1,
23+
optional: true,
24+
},
25+
entityId: {
26+
type: "string",
27+
label: "Entity ID",
28+
description: "Unique entity identifier",
29+
optional: true,
30+
},
31+
datasetQuery: {
32+
type: "object",
33+
label: "Dataset Query",
34+
description: "The query definition object. For native queries, use `{\"native\": {\"query\": \"SELECT * FROM table\"}}`. For structured queries, provide the query object.",
35+
},
36+
parameterMappings: {
37+
type: "string[]",
38+
label: "Parameter Mappings",
39+
description: "Array of parameter mapping objects. Each mapping must include `parameter_id` (string) and `target` (object) keys. Optionally include `card_id` (integer > 0). Example: `[{\"parameter_id\": \"date_filter\", \"target\": \"target\", \"card_id\": 456}]`",
40+
optional: true,
41+
},
42+
name: {
43+
type: "string",
44+
label: "Name",
45+
description: "The name of the card (required)",
46+
},
47+
collectionPosition: {
48+
type: "integer",
49+
label: "Collection Position",
50+
description: "Position within the collection (must be greater than zero)",
51+
min: 1,
52+
optional: true,
53+
},
54+
resultMetadata: {
55+
type: "string[]",
56+
label: "Result Metadata",
57+
description: "Array of metadata objects describing query result columns. Each object contains information about column names, types, and display properties. Example: `[{\"name\": \"id\", \"display_name\": \"ID\", \"base_type\": \"keyworkd\", \"semantic_type\": \"keyword\"}]`",
58+
optional: true,
59+
},
60+
collectionId: {
61+
propDefinition: [
62+
app,
63+
"collectionId",
64+
],
65+
optional: true,
66+
},
67+
cacheTtl: {
68+
type: "integer",
69+
label: "Cache TTL",
70+
description: "Cache time-to-live in seconds (must be greater than zero)",
71+
min: 1,
72+
optional: true,
73+
},
74+
type: {
75+
type: "string",
76+
label: "Card Type",
77+
description: "The type of card",
78+
options: [
79+
"question",
80+
"metric",
81+
"model",
82+
],
83+
optional: true,
84+
},
85+
display: {
86+
type: "string",
87+
label: "Display Type",
88+
description: "The type of visualization (required)",
89+
options: VISUALIZATION_TYPES,
90+
},
91+
parameters: {
92+
type: "string[]",
93+
label: "Parameters",
94+
description: "Array of parameter definition objects. Each parameter must include `id` (string) and `type` (string) keys. Optional properties: `name`, `slug`, `sectionId`, `default`, `values_source_type` (\"static-list\", \"card\", or null), `values_source_config` (object with `card_id`, `label_field`, `value_field`, `values`), and `temporal_units` (array). Example: `[{\"id\": \"date_param\", \"type\": \"date/single\", \"name\": \"Date Filter\", \"slug\": \"date_filter\", \"default\": \"2024-01-01\", \"values_source_type\": \"static-list\"}]`",
95+
optional: true,
96+
},
97+
description: {
98+
type: "string",
99+
label: "Description",
100+
description: "Description of the card",
101+
optional: true,
102+
},
103+
dashboardId: {
104+
propDefinition: [
105+
app,
106+
"dashboardId",
107+
],
108+
optional: true,
109+
},
110+
},
111+
async run({ $ }) {
112+
const {
113+
app,
114+
name,
115+
datasetQuery,
116+
display,
117+
visualizationSettings,
118+
type,
119+
collectionId,
120+
description,
121+
collectionPosition,
122+
cacheTtl,
123+
entityId,
124+
dashboardId,
125+
dashboardTabId,
126+
parameters,
127+
parameterMappings,
128+
resultMetadata,
129+
} = this;
130+
131+
const response = await app.createCard({
132+
$,
133+
data: {
134+
name,
135+
dataset_query: datasetQuery,
136+
display,
137+
visualization_settings: utils.parseJson(visualizationSettings),
138+
type,
139+
collection_id: collectionId,
140+
description,
141+
collection_position: collectionPosition,
142+
cache_ttl: cacheTtl,
143+
entity_id: entityId,
144+
dashboard_id: dashboardId,
145+
dashboard_tab_id: dashboardTabId,
146+
parameters: utils.parseArray(parameters),
147+
parameter_mappings: utils.parseArray(parameterMappings),
148+
result_metadata: utils.parseArray(resultMetadata),
149+
},
150+
});
151+
152+
$.export("$summary", "Successfully created card");
153+
154+
return response;
155+
},
156+
};
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import app from "../../metabase.app.mjs";
2+
import utils from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "metabase-create-dashboard",
6+
name: "Create Dashboard",
7+
description: "Create a new Dashboard. [See the documentation](https://www.metabase.com/docs/latest/api#tag/apidashboard/post/api/dashboard/).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
name: {
13+
type: "string",
14+
label: "Name",
15+
description: "The name of the dashboard",
16+
},
17+
description: {
18+
type: "string",
19+
label: "Description",
20+
description: "Description of the dashboard",
21+
optional: true,
22+
},
23+
collectionId: {
24+
propDefinition: [
25+
app,
26+
"collectionId",
27+
],
28+
optional: true,
29+
},
30+
collectionPosition: {
31+
type: "integer",
32+
label: "Collection Position",
33+
description: "Position within the collection (must be greater than zero)",
34+
min: 1,
35+
optional: true,
36+
},
37+
cacheTtl: {
38+
type: "integer",
39+
label: "Cache TTL",
40+
description: "Cache time-to-live in seconds (must be greater than zero)",
41+
min: 1,
42+
optional: true,
43+
},
44+
parameters: {
45+
type: "string[]",
46+
label: "Parameters",
47+
description: "Array of parameter definition objects. Each parameter must include `id` (string) and `type` (string) keys. Optional properties: `name`, `slug`, `sectionId`, `default`, `values_source_type` (\"static-list\", \"card\", or null), `values_source_config` (object with `card_id`, `label_field`, `value_field`, `values`), and `temporal_units` (array). Example: `[{\"id\": \"date_param\", \"type\": \"date/single\", \"name\": \"Date Filter\", \"slug\": \"date_filter\", \"default\": \"2024-01-01\", \"values_source_type\": \"static-list\"}]`",
48+
optional: true,
49+
},
50+
},
51+
async run({ $ }) {
52+
const {
53+
app,
54+
name,
55+
description,
56+
collectionId,
57+
collectionPosition,
58+
cacheTtl,
59+
parameters,
60+
} = this;
61+
62+
const response = await app.createDashboard({
63+
$,
64+
data: {
65+
name,
66+
description,
67+
collection_id: collectionId,
68+
collection_position: collectionPosition,
69+
cache_ttl: cacheTtl,
70+
parameters: utils.parseArray(parameters),
71+
},
72+
});
73+
74+
$.export("$summary", "Successfully created dashboard");
75+
76+
return response;
77+
},
78+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import app from "../../metabase.app.mjs";
2+
3+
export default {
4+
key: "metabase-get-dashboard",
5+
name: "Get Dashboard",
6+
description: "Retrieve dashboard information and its cards. [See the documentation](https://www.metabase.com/docs/latest/api#tag/apidashboard/get/api/dashboard/{id}).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
dashboardId: {
12+
propDefinition: [
13+
app,
14+
"dashboardId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const {
20+
app,
21+
dashboardId,
22+
} = this;
23+
24+
const response = await app.getDashboard({
25+
$,
26+
dashboardId,
27+
});
28+
29+
$.export("$summary", "Successfully retrieved dashboard");
30+
31+
return response;
32+
},
33+
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import app from "../../metabase.app.mjs";
2+
3+
export default {
4+
key: "metabase-get-database",
5+
name: "Get Database",
6+
description: "Retrieve database information. [See the documentation](https://www.metabase.com/docs/latest/api#tag/apidatabase/get/api/database/{id}).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
databaseId: {
12+
propDefinition: [
13+
app,
14+
"databaseId",
15+
],
16+
},
17+
include: {
18+
type: "string",
19+
label: "Include",
20+
description: "What to include in the response",
21+
options: [
22+
"tables",
23+
"tables.fields",
24+
],
25+
optional: true,
26+
},
27+
includeEditableDataModel: {
28+
type: "boolean",
29+
label: "Include Editable Data Model",
30+
description: "Whether to include editable data model information",
31+
optional: true,
32+
},
33+
excludeUneditableDetails: {
34+
type: "boolean",
35+
label: "Exclude Uneditable Details",
36+
description: "Whether to exclude uneditable details from the response",
37+
optional: true,
38+
},
39+
},
40+
async run({ $ }) {
41+
const {
42+
app,
43+
databaseId,
44+
include,
45+
includeEditableDataModel,
46+
excludeUneditableDetails,
47+
} = this;
48+
49+
const response = await app.getDatabase({
50+
$,
51+
databaseId,
52+
params: {
53+
include,
54+
include_editable_data_model: includeEditableDataModel,
55+
exclude_uneditable_details: excludeUneditableDetails,
56+
},
57+
});
58+
59+
$.export("$summary", "Successfully retrieved database information");
60+
61+
return response;
62+
},
63+
};

0 commit comments

Comments
 (0)