I’m running Metabase 0.49 and I’d like to add tabs to a dashboard programmatically instead of creating them manually in the UI.
I’ve reviewed the API endpoints for dashboards, cards, and parameters, but I can’t find clear documentation on:
Which API endpoint handles creating and managing dashboard tabs.
Whether tabs are created via the /api/dashboard endpoint with a specific payload, or if there’s a separate /api/dashboard-tab (or similar) endpoint.
The required JSON structure for creating a tab and assigning cards to it.
I’ve already tried updating the dashboard with the PUT /api/dashboard/:id endpoint (as per the docs) by adding tab-related fields to the payload, but it does not create a new tab
My goal is to automate dashboard creation from a script, including multiple tabs with different cards.
If anyone has examples of API requests for creating tabs in 0.49, that would be a huge help.
Thanks for your answer.
Yes this I know, I can access the tabs id though this. But what I want is to duplicated a dashboard, creating the exact same number of tabs before attaching duplicated cards to it.
But even with the information on dashboard_tab_id, there is no “post” endpoint that can post a tab based on an ID. Well at least I didn’t find it..
Looking at what the frontend does when it creates a new tab, it calls PUT /api/dashboard/:id and for the new tab uses the magic -2. The response returns the updated dashboard object but the tab will have a new ID filled in.
Using the hint of dwhitemv I could not make this work, I created function looking like this:
`def create_dashboard_tab(mb: Metabase,
dashboard_id: int,
name: str,
description: Union[None, str] = None,
raise_error: bool = True) -> dict:
"""Create a new tab in a dashboard using magic id -2 (Metabase Cloud).
Args:
mb (Metabase): metabase object
dashboard_id (int): ID of the dashboard
name (str): name of the new tab
description (None|str): description of the tab (optional)
raise_error (bool): raise if API call fails
Returns:
dict: Updated dashboard object with the new tab
"""
payload = {"tabs": [{"id": -2, "name": name, "description": description or ""}]}
url = f"/dashboard/{dashboard_id}"
resp = mb.put(url, json=payload) # retourne juste un bool
if raise_error:
_raise_resp(resp, request_type="put", url=mb.endpoint + url, params=payload)`
Put it was not duplicating the tabs of my dashboard in a new one, even if tabs were detected.
@abilash , so you did’nt use any put method on tabs, just on cards, and it was creating tabs within a dashboard ? I can’t see how this works if you didn”t created tabs before
Yes, I only used the PUT /api/dashboard/{id}/cards endpoint and it worked for me. Maybe the tabs are just a logical grouping, but with that payload containing only cards, everything works fine on my end. Earlier, I had even tried using the special -2 as the tab ID, but that didn’t help.