cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to schedule/refresh databricks alerts using REST API?

Abhiqa
New Contributor II

Hi, I am deploying Databricks SQL alerts using REST API. But I can't seem to figure out how to schedule their refresh task.

I went through the documentation it says "Alerts can be scheduled using the sql_task type of the Jobs API, e.g. Jobs/Create"

Abhiqa_0-1697550139434.png

However, in the sql_task of the jobs API, there is no example of scheduling sql_task (query or alert). Having said that, I also tried to schedule using the "Schedule" key of job api eg

"schedule": {
                    "quartz_cron_expression": "0 0 0/4 * * ?",
                    "timezone_id": "US/Mountain",
                    "pause_status": "UNPAUSED"
                }
still no luck, 

Could you please help me by giving a working example of scheduling a refresh for an alert payload, so alert schedule appears in the below screen? Thank you very much
Abhiqa_1-1697550638337.png

 

 

1 REPLY 1

btafur
Databricks Employee
Databricks Employee

What they mention in the API docs is that you can create a job with sql_task of type Alert. To make it easier you can try creating the job first in the UI first and downloading the JSON config. Here is an example with the main parameters that should work for what you are trying to do:

{
    "job_id": 1111,
    ...
    "settings": {
        "name": "test_sql_task",
        ...
        "schedule": {
            "quartz_cron_expression": "34 30 20 * * ?",
            "timezone_id": "UTC",
            "pause_status": "UNPAUSED"
        },
        "tasks": [
            {
                "task_key": "test_sql_task",
                "run_if": "ALL_SUCCESS",
                "sql_task": {
                    "alert": {
                        "alert_id": "009f4ff1-0493-4e58-9224-7ea4dcca0f99",
                        "subscriptions": [
                            {
                                "user_name": "test@email.com"
                            }
                        ]
                    },
                    "warehouse_id": "475b94ddc7cd5211"
                }
            }
        ],
        ...
    }
}

 

 

 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group