Create Notification Policies via REST-API (No Post Method)

There is no POST method for creating a notification policy

  • What happened?
    I am getting a 404 not found error.

  • What did you expect to happen?
    I expected the Notification Policy to be created
    But I also noticed that the http provisioning docs leave out the POST method for creating a notification policy. DELETE, GET, and PUT exist but not POST

  • Can you copy/paste the configuration(s) that you are having problems with?

endpoint = "<grafana-url>/api/v1/provisioning/policies"

payload = {        
        "receiver": "test_alert_name",
        "object_matchers": [ ],
        "routes": [
            {
                "receiver": "test_alert_name",
                "object_matchers": [["alertname", "=", "scanappAlert"]],
            }
        ],
    }

Sending a post request and getting a 404 Not found error

Hey @krilling - I was having the same issue until I realized notification policies are a tree. You can only update the existing tree with a PUT rather than create a new tree with a POST. What I did in my case was replace the root policy with a new one the update the tree with new policies.

curl --location --request PUT 'https://inseryourdomain/api/v1/provisioning/policies' \
--header 'Content-Type: application/json' \
--data
'{
    "receiver": "email_notifications",
    "group_by": [
        "grafana_folder",
        "alertname"
    ],
    "routes": [
        {
            "receiver": "email_notifications",
            "object_matchers": [
                [
                    "severity",
                    "=",
                    "critical"
                ]
            ],
            "continue": true
        }
]
}'