cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Warehousing & Analytics
Engage in discussions on data warehousing, analytics, and BI solutions within the Databricks Community. Share insights, tips, and best practices for leveraging data for informed decision-making.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Databricks dashboard email with attachment

yanchr
New Contributor III

I'm trying to manage a scheduled AI/BI dashboard email entirely through Terraform and the API. The goal is to send a monthly PDF snapshot of the dashboard, with specific filter values already applied, to a list of subscribers and specified attachments.
What I found:
The Lakeview API create subscription lets me add subscribers to a dashboard schedule. As far as I can tell, subscribers are all it exposes. I don't see a way to choose which filter values or parameters are included in the emailed snapshot.
Jobs API. Create job has a dashboard_task that takes dashboard_id, warehouse_id, subscription and filters. The Terraform provider exposes the same fields. So a job can refresh the dashboard, apply filters and notify subscribers.Is there a way to define custom attachments declaratively via the API/Terraform?

2 REPLIES 2

Isaac_18
Contributor

Hi @yanchr, you've read the APIs right. The Lakeview schedule and subscription endpoints only cover the cron, the warehouse and who gets the email. There's no field there for filter values or attachments.

The dashboard task in Lakeflow Jobs is the place to do this, and it now covers attachments too. In the Jobs API, dashboard_task.subscription has an attachment object (still marked Beta) with two parts:

  • page_attachment picks which pages go into the PDF. Without it you only get the first page.
  • data_attachment attaches the data behind up to 5 widgets as CSV, TSV or Excel, and can add the applied filter values as an extra file.

Filters go in dashboard_task.filters, keyed by each filter widget's URL identifier. Here's roughly what a monthly job looks like as a Jobs API payload:

{
  "name": "monthly-sales-snapshot",
  "schedule": {
    "quartz_cron_expression": "0 0 7 1 * ?",
    "timezone_id": "Europe/London"
  },
  "tasks": [
    {
      "task_key": "send_snapshot",
      "dashboard_task": {
        "dashboard_id": "<dashboard-id>",
        "warehouse_id": "<warehouse-id>",
        "filters": {
          "region": "EMEA",
          "product_line": "[\"Hardware\",\"Services\"]"
        },
        "subscription": {
          "custom_subject": "Monthly sales snapshot (EMEA)",
          "subscribers": [
            { "user_name": "someone@yourcompany.com" },
            { "destination_id": "<email-destination-id>" }
          ],
          "attachment": {
            "page_attachment": {
              "page_selection": "PAGE_SELECTION_SUBSET",
              "page_ids": ["overview", "regional_detail"]
            },
            "data_attachment": {
              "widgets": [
                { "page_id": "regional_detail", "widget_id": "sales_by_country" }
              ],
              "file_format": "FILE_FORMAT_EXCEL",
              "include_applied_filters": true
            }
          }
        }
      }
    }
  ]
}

A few things that are easy to miss:

  • page_id and widget_id aren't the titles you see on the canvas. They're the name values in the dashboard's serialized_dashboard (from the Get dashboard API, or the .lvdash.json file if you keep it in source control).
  • Multi-select filters take a JSON array as a string, like "[\"a\",\"b\"]". Date filters take ISO 8601.
  • Dataset parameters can't be set directly in the task. Attach the parameter to a filter widget on the canvas, then set that filter in the task.
  • The warehouse has to be serverless or pro.
  • This subscriber list is separate from the dashboard's own schedules, so people won't get a second email unless they're in both.

For Terraform: Declarative Automation Bundles already accept the attachment block in the dashboard task schema. The Terraform databricks_job resource generates its schema from the Go SDK, which has the field, but the provider docs don't mention it yet. Before relying on it, I'd upgrade to a recent provider and run terraform providers schema -json | grep page_attachment to confirm. If it isn't there in your version, you can keep the job in a bundle, or manage it with the Jobs API from your pipeline until the provider catches up.

Docs: dashboard task for jobs (https://docs.databricks.com/aws/en/jobs/dashboard) and the Jobs create API (https://docs.databricks.com/api/workspace/jobs/create), see dashboard_task.subscription.attachment.

Hope this saves you some digging. If it works for you, marking it as the solution helps the next person find it.

data_pulse
Contributor

@yanchr 

I validated this using Lakeflow Jobs Dashboard tasks, the Jobs REST API and the Databricks Terraform provider. Here are the options I have tried and the findings:

1: Lakeflow Jobs Dashboard task (simplest approach)

Option A : Configure through UI

The Dashboard task UI provides attachment configuration directly.

Navigate to Jobs & Pipelines โ†’ Job โ†’ Tasks โ†’ Dashboard task.

You can configure:

  • Subscribers: Recipients who should receive the dashboard email.
  • Dashboard filters: Apply specific filter values before generating the dashboard snapshot.
  • Include pages: Select dashboard pages to attach as PDF.
  • Include data: Select widgets and export their data as CSV, TSV, or Excel.

What I validated:

Using an existing dashboard task, I verified that the UI exposes Include pages and Include data, with page/widget selection and CSV, TSV, and Excel format options.

The UI also correctly displayed attachment settings previously configured through the Jobs API.

Option B : Configure through Databricks Asset Bundles (YAML) 

The equivalent bundle configuration is: 

resources:
  jobs:
    dashboard_email_job:
      name: dashboard-email-with-attachments
      tasks:
        - task_key: dashboard_snapshot
          dashboard_task:
            dashboard_id: ${var.dashboard_id}
            warehouse_id: ${var.warehouse_id}
            subscription:
              subscribers:
                - user_name: user@example.com
              attachment:
                data_attachment:
                  widgets:
                    - page_id: page_99999
                      widget_id: bar_99999
                  file_format: FILE_FORMAT_CSV

Mention that FILE_FORMAT_EXCEL and FILE_FORMAT_TSV are alternative values.

2: Jobs REST API (tested end-to-end)

For programmatic config, the Jobs API supports attachments under: dashboard_task.subscription.attachment

Here's a minimal example:

{
  "name": "dashboard-email-with-attachments",
  "tasks": [
    {
      "task_key": "send_dashboard",
      "dashboard_task": {
        "dashboard_id": "YOUR_DASHBOARD_ID",
        "warehouse_id": "YOUR_WAREHOUSE_ID",
        "subscription": {
          "paused": false,
          "subscribers": [
            {
              "user_name": "user@example.com"
            }
          ],
          "attachment": {
            "page_attachment": {
              "page_selection": "PAGE_SELECTION_SUBSET",
              "page_ids": ["YOUR_PAGE_ID"]
            },
            "data_attachment": {
              "file_format": "FILE_FORMAT_CSV",
              "widgets": [
                {
                  "page_id": "YOUR_PAGE_ID",
                  "widget_id": "YOUR_WIDGET_ID"
                }
              ],
              "include_applied_filters": true
            }
          }
        }
      }
    }
  ]
}

Submit the payload using:

curl -X POST \
  "$DATABRICKS_HOST/api/2.2/jobs/create" \
  -H "Authorization: Bearer $DATABRICKS_TOKEN" \
  -H "Content-Type: application/json" \
  --data-binary @job.json

You can then verify the saved configuration using:

databricks jobs get <job-id> --output json

My Actual test results:

  • Jobs API accepted the PDF page and CSV widget attachment configuration.
  • GET response retained both attachment objects.
  • Dashboard task execution completed with Success .
  • Email delivery was confirmed.
  • The received email contained both a PDF attachment and a tabular-data attachment

data_pulse_0-1793439656917.png

data_pulse_1-1793439696495.png

3:Terraform : Native Attachment Support (v1.140.0)

I also tested the Databricks Terraform provider versions v1.109.0 and v1.137.0.

Both terraform validate and terraform plan failed with:

Error: Unsupported block type
Blocks of type "attachment" are not expected here.

But, The latest tested provider, v1.140.0 (published October 26, 2026), exposes native page_attachment and data_attachment blocks under dashboard_task.subscription.attachment.

supported Terraform structure:

resource "databricks_job" "dashboard_email" {
  name = "dashboard-email-with-attachments"

  task {
    task_key = "dashboard_snapshot"

    dashboard_task {
      dashboard_id = var.dashboard_id
      warehouse_id = var.warehouse_id
      subscription {
        paused = true
        subscribers {
          user_name = var.recipient_email
        }
        attachment {
          page_attachment {
            page_selection = "PAGE_SELECTION_SUBSET"
            page_ids       = ["page_99999"]
          }

          data_attachment {
            file_format             = "FILE_FORMAT_CSV"
            include_applied_filters = true
            widgets {
              page_id   = "page_99999"
              widget_id = "bar_99999"
            }
          }
        }
      }
    }
  }
}

Validation: I successfully deployed the dashboard job using Terraform provider v1.140.0 with native PDF/CSV attachment configuration. terraform validate, plan, and apply all passed. The Jobs API confirmed the attachment settings were retained, the dashboard task run completed with SUCCESS and email delivery also confirmed.

Recommendation: For straightforward scheduled dashboard emails, use the Lakeflow Jobs Dashboard task UI, which supports PDF page and widget-data attachments.

For declarative automation, Terraform provider v1.140.0 is a validated option, with successful deployment, execution, and email receipt confirmed.

The Jobs REST API remains an alternative for programmatic configs or older Terraform provider versions that lack native attachment support.

References:

Dashboard task for Lakeflow Jobs

Jobs REST API