Add TextCard to Dashboard with API

I need to add a TextCard to an already created dashboard using the Metabase API. According to the documentation I could use PUT /api/dashboard/:id/cards with this body:

{:cards [{:id     ...
      :sizeX  ...
      :sizeY  ...
      :row    ...
      :col    ...
      :series [{:id 123
                ...}]} ...]}

So far I’ve tried this with the Metabase Python library:

payload = {
    "id": new_dashboard_id,
    "cards": [{
        "row": 0,
        "col": 0,
        "sizeX": 5,
        "sizeY": 2,
        "parameter_mappings": [],
        "visualization_settings": {
            "virtual_card": {
                "display": "text",
                "visualization_settings": {},
                "dataset_query": {},
            "text.align_vertical": "middle",
            "text.align_horizontal": "center",
            "text": "Sample text"
metabase.put('/dashboard/10/cards', json=payload)

I’ve also tried using POST and dashboard-card removing the [ ] part of cards, with no avail. At most I get a blank rectangle with the keys symbol (no permission to see the card)

Any clues on the correct syntax for achieving this?


Hi @rodabt
The best way to learn the API, is to just use Metabase while having your browser developer Network-tab open and looking at the request, and what data is being send/received.
You first need to create the card with POST /api/dashboard/:id/cards, which then returns the ID of the card, which you then uses to fill in the details with PUT /api/dashboard/:id/cards