โ01-27-2025 08:07 AM
Hi All, I'm trying to create an alert using the Databricks REST API, but I keep encountering the following error:
Error creating alert: 400 {"message": "Alert name cannot be empty or whitespace"}:
{
"alert": {
"seconds_to_retrigger": 0,
"display_name": "AlertTest",
"condition": {
"op": "EQUAL",
"operand": {
"column": {
"name": "Id"
}
},
"threshold": {
"value": {
"double_value": 1
}
}
},
"query_id": "123e4567-e89b-12d3-a456-426614174000",
"parent_path": "/Workspace/Users/user@mail.com"
}
}
โ01-28-2025 02:03 AM
Hi @zg ,
You are sending the payload related to the new endpoint (/api/2.0/sql/alerts) to the old endpoint (/api/2.0/preview/sql/alerts).
That are the docs of the old endpoint:
https://docs.databricks.com/api/workspace/alertslegacy/create
As you can see the field is called "name"
In the new endpoint the name is called "display_name":
https://docs.databricks.com/api/workspace/alerts/create
To sum up, just change your endpoint from /api/2.0/preview/sql/alerts to /api/2.0/sql/alerts and it should work.
โ01-28-2025 02:30 AM
You're absolutely right! Even though I had tried it before, it didnโt work initially. However, I resolved the problem by reviewing the API's structure using the UI. By following the same structure and defining a new alert condition, it worked without any errors. Here's the code I used:
import requests
import json
# Databricks API Details
HOST = "https://<databricks-workspace>.azuredatabricks.net"
TOKEN = "token"
ENDPOINT = f"{HOST}/api/2.0/sql/alerts"
# Function to check the alert API
def check_alert_api():
headers = {
"Authorization": f"Bearer {TOKEN}"
}
response = requests.get(ENDPOINT, headers=headers)
print("Response Data:", json.dumps(response.json(), indent=4))
# Execute the function
check_alert_api()
โ01-27-2025 09:27 AM
Hi @zg,
Could you please share the REST API Endpoint you are making the request to?
โ01-28-2025 01:06 AM
Hello @Alberto_Umana,
Thank you for your response. The REST API Endpoint I am using for this request is:
https://<databricks-workspace>.azuredatabricks.net/api/2.0/preview/sql/alerts.
Please let me know if you need additional details.
Best regards
โ01-28-2025 02:03 AM
Hi @zg ,
You are sending the payload related to the new endpoint (/api/2.0/sql/alerts) to the old endpoint (/api/2.0/preview/sql/alerts).
That are the docs of the old endpoint:
https://docs.databricks.com/api/workspace/alertslegacy/create
As you can see the field is called "name"
In the new endpoint the name is called "display_name":
https://docs.databricks.com/api/workspace/alerts/create
To sum up, just change your endpoint from /api/2.0/preview/sql/alerts to /api/2.0/sql/alerts and it should work.
โ01-28-2025 02:30 AM
You're absolutely right! Even though I had tried it before, it didnโt work initially. However, I resolved the problem by reviewing the API's structure using the UI. By following the same structure and defining a new alert condition, it worked without any errors. Here's the code I used:
import requests
import json
# Databricks API Details
HOST = "https://<databricks-workspace>.azuredatabricks.net"
TOKEN = "token"
ENDPOINT = f"{HOST}/api/2.0/sql/alerts"
# Function to check the alert API
def check_alert_api():
headers = {
"Authorization": f"Bearer {TOKEN}"
}
response = requests.get(ENDPOINT, headers=headers)
print("Response Data:", json.dumps(response.json(), indent=4))
# Execute the function
check_alert_api()
Passionate about hosting events and connecting people? Help us grow a vibrant local communityโsign up today to get started!
Sign Up Now