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

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
Contributor III
Contributor III

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"
                }
            }
        ],
        ...
    }
}

 

 

 

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!