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?

3 REPLIES 3

Isaac_18
Contributor II

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

Louis_Frolio
Databricks Employee
Databricks Employee

Greetings @yanchr, I did some digging and here is what I found.

Short answer: yes. @Isaac_18 and @data_pulse have it right, and their answers hold up against the current docs. The Lakeview subscription API only controls who gets the email. The dashboard task in Lakeflow Jobs is where the content is set: filter values under dashboard_task.filters, and attachments under dashboard_task.subscription.attachment (page_attachment for the PDF pages, data_attachment for widget data). Isaac's payload and data_pulse's HCL are good templates, so I won't repeat them.

On Terraform, data_pulse's finding checks out. The v1.140.0 provider source includes the attachment types, and older versions reject the block. Confirm against the version you have pinned:

terraform providers schema -json | grep -E '"page_attachment"|"data_attachment"'

If the block isn't there, a bundle or a direct Jobs API call gets you the same result. Isaac also noted the attachment object is marked Beta, so pin your provider version and re-check after upgrades.

A few things the thread hasn't covered yet:

  • "Custom" attachments: these are limited to content from the dashboard itself. That's up to 15 pages in the PDF (first page only if you pick none), data from up to 5 widgets as CSV, TSV, or Excel, and an optional file of the applied filter values. Attaching an arbitrary file from outside the dashboard isn't supported.
  • Size limits: all attachments share a 9 MB cap per email, and Excel stops at 100,000 rows. Over the cap, the data files are dropped and only the PDF goes out.
  • Monthly values: if a filter's URL Identifier matches a job-level parameter key, the task applies that parameter's value. The reporting period can come from a job parameter instead of a value you edit every month.
  • Run as: the dashboard has to be published. Without shared data permissions, the job's Run as identity refreshes it, so that identity (often a service principal in a Terraform setup) needs access to the data. With shared data permissions, the publisher's credentials are used.
  • Filters aren't a security boundary: they shape the snapshot, but anyone who can open the dashboard can change them. Use row filters and column masks in Unity Catalog if recipients should only see certain rows.

References:

If you found this answer helpful please check off "Accept as Solutions" so that others can have confidence in the answer.

Regards, Louis.