Create an Alert via CURL / bash script


Has anyone done this?

I’m finding it difficult… this is what i’ve got so far:

curl -H “Content-Type: application/json” -ksvX POST -d ‘{“name”:“test”,“type”:“email”,“isDefault”:“false”}’ ‘http://admin:admin@localhost:3000/api/alerts-notifications

I get HTTP/1.1 404 Not Found

Unsure how to specify the graph panel and time of alert?

Thanks in advance


So I’m guessing you want to create an alert for a specific panel in a specific dashboard.

The api endpoint api/alerts-notifications is not to be used for that. It’s for creating new notification channels.

The way you currently can do this thru the api is to use the create/update dashboard endpoint.


Marcus, it’s unclear from the link you have shared how to create alerts. At least, I could not find anything which talks about alerts. Can you elaborate?


If you use Grafana’s graphical interface you can create dashboards. Each dashboard can hold X number of panels. If you have a panel in edit mode there is a tab called Alerts where you configure rules of your alert, see alerting documentation. After you’ve added your alerts to panels they’re now included in the dashboard json model. When you saves the dashboard the dashboard json model will be persisted to the database. This is also were the alerts are extracted from the dashboard json model and actual alerts are persisted (different database table) - first after this step you’ll see your alerts on the Alert Rules page in Grafana.

So to elaborate on using the api for creating alerts you’ll need a proper dashboard json model and send it in to the create/update dashboard endpoint referenced above. The easiest way of getting the dashboard json model is to navigate to a dashboard -> Settings -> View json and/or fetching the dashboard from the api using a HTTP GET. You can then use this dashboard json model to make updates to the dashboard and the alerts using the create/update dashboard endpoint.

We’re lacking some documentation about how the actual json representation of alert rules are represented in dashboards, but the easiest to get to know this would be to show the json of a dashboard having alerts defined.

If you want to automate and script dashboards there are a few projects like [grafonnet],( and grafanalib and Wizzy to name a few.

Hope this make it more clearer


Hello Marcus
Can we use the grafana create API to create alert to the Panel when we are creating a dashboard for the first time.

I am trying to do so and getting the following error

Grafana Response Status(422) for /api/dashboards/db: {"message":"alert validation error: \"evaluate every\" field could not be parsed"}

Do I need to create a dashboard and then use the API to add the alert.

Can the alert not be a part of the JSON which is being used to create the dashboard ?