This is documentation for the next version of Grafana documentation. For the latest stable release, go to the latest version.

Enterprise Open source Grafana Cloud

Create a contact point and an alert rule

This tutorial walks through an end-to-end Grafana Alerting workflow using /apis endpoints: testing and creating a webhook contact point (Receiver), creating a folder (Folder), provisioning a Grafana-managed alert rule (AlertRule) routed directly to that contact point, and pausing or inspecting the rule.

Every request has two tabs: one for curl and one for gcx. Both send the same HTTP API request.

This workflow combines three /apis groups:

  • Alert notifications HTTP API (notifications.alerting.grafana.app/v1beta1): Tests and manages contact points (receivers).
  • Folder HTTP API (folder.grafana.app/v1): Creates the folder that holds the alert rule.
  • Alert rules HTTP API (rules.alerting.grafana.app/v1beta1): Creates, inspects, pauses, and deletes standalone alert rules (alertrules).

Note

The notifications.alerting.grafana.app/v1beta1 (Grafana 13.0 and later) and rules.alerting.grafana.app/v1beta1 (Grafana 13.3 and later) APIs are in beta. Verify that both API groups are available on /swagger in your Grafana instance before running these commands.

Before you begin

Before you begin, ensure you have the following:

  • A Grafana instance: Access to Grafana Cloud, Grafana Enterprise, or Grafana OSS with Grafana Alerting enabled.
  • A service account token: A token with permissions to create folders, contact points, and alert rules, and to query the target data source (for example, the Editor or Admin basic role). Refer to Configure RBAC for Grafana Alerting.
  • A Prometheus data source UID: The uid of a Prometheus data source in your instance (list data sources with GET /api/datasources if you need to look it up).
  • A command-line tool: curl or gcx installed locally, plus jq to filter JSON output.

Export your environment variables for the session:

sh
export GRAFANA_URL="<GRAFANA_URL>"
export GRAFANA_TOKEN="<SERVICE_ACCOUNT_TOKEN>"
export GRAFANA_NAMESPACE="<NAMESPACE>"

Replace the placeholders as follows:

  • <GRAFANA_URL>: Base URL of your Grafana instance without a trailing slash, such as https://my-stack.grafana.net or http://localhost:3000.
  • <SERVICE_ACCOUNT_TOKEN>: Bearer token for your service account.
  • <NAMESPACE>: Resource namespace for /apis paths: stacks-<STACK_ID> in Grafana Cloud, default for organization 1 in self-managed Grafana, or org-<ORG_ID> for another organization.

If you use gcx, sign in once for the session (add --org-id <ORG_ID> when your namespace is org-<ORG_ID>):

sh
gcx login --server "$GRAFANA_URL" --token "$GRAFANA_TOKEN" --yes

Step 1: Test and create a contact point

Create the contact point before creating the alert rule, because Grafana validates that any receiver referenced by an alert rule already exists.

Send a test notification before saving

Call POST /apis/notifications.alerting.grafana.app/v1beta1/namespaces/{namespace}/receivers/-/test with - as the receiver name to verify that your webhook endpoint is reachable before persisting the contact point:

curl
curl -sS -X POST \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GRAFANA_TOKEN" \
  -d '{
    "integration": {
      "type": "webhook",
      "version": "1",
      "settings": {
        "url": "<WEBHOOK_URL>",
        "httpMethod": "POST"
      }
    },
    "alert": {
      "labels": {
        "alertname": "WebhookConnectivityTest",
        "severity": "warning"
      },
      "annotations": {
        "summary": "Verifying webhook delivery from Grafana Alerting"
      }
    }
  }' \
  "$GRAFANA_URL/apis/notifications.alerting.grafana.app/v1beta1/namespaces/$GRAFANA_NAMESPACE/receivers/-/test"
gcx
gcx api "/apis/notifications.alerting.grafana.app/v1beta1/namespaces/$GRAFANA_NAMESPACE/receivers/-/test" \
  -d '{
    "integration": {
      "type": "webhook",
      "version": "1",
      "settings": {
        "url": "<WEBHOOK_URL>",
        "httpMethod": "POST"
      }
    },
    "alert": {
      "labels": {
        "alertname": "WebhookConnectivityTest",
        "severity": "warning"
      },
      "annotations": {
        "summary": "Verifying webhook delivery from Grafana Alerting"
      }
    }
  }'

Replace <WEBHOOK_URL> with the HTTPS or HTTP endpoint that receives your alert payloads.

A successful delivery returns 200 OK:

JSON
{
  "status": "success",
  "duration": "118ms"
}

Save the contact point

Call POST /apis/notifications.alerting.grafana.app/v1beta1/namespaces/{namespace}/receivers to create the Receiver resource:

curl
curl -sS -X POST \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GRAFANA_TOKEN" \
  -d '{
    "apiVersion": "notifications.alerting.grafana.app/v1beta1",
    "kind": "Receiver",
    "metadata": {
      "name": "oncall-webhook"
    },
    "spec": {
      "title": "On-call webhook",
      "integrations": [
        {
          "type": "webhook",
          "version": "1",
          "disableResolveMessage": false,
          "settings": {
            "url": "<WEBHOOK_URL>",
            "httpMethod": "POST"
          }
        }
      ]
    }
  }' \
  "$GRAFANA_URL/apis/notifications.alerting.grafana.app/v1beta1/namespaces/$GRAFANA_NAMESPACE/receivers"
gcx
gcx api "/apis/notifications.alerting.grafana.app/v1beta1/namespaces/$GRAFANA_NAMESPACE/receivers" \
  -d '{
    "apiVersion": "notifications.alerting.grafana.app/v1beta1",
    "kind": "Receiver",
    "metadata": {
      "name": "oncall-webhook"
    },
    "spec": {
      "title": "On-call webhook",
      "integrations": [
        {
          "type": "webhook",
          "version": "1",
          "disableResolveMessage": false,
          "settings": {
            "url": "<WEBHOOK_URL>",
            "httpMethod": "POST"
          }
        }
      ]
    }
  }'

Replace <WEBHOOK_URL> with your webhook endpoint URL.

Grafana returns 201 Created with the saved Receiver resource:

JSON
{
  "kind": "Receiver",
  "apiVersion": "notifications.alerting.grafana.app/v1beta1",
  "metadata": {
    "name": "oncall-webhook",
    "namespace": "default",
    "uid": "7f3a9d2e-1b4c-4e8a-9c0d-2f4b6e8a0c12",
    "resourceVersion": "a1b2c3d4e5f60718"
  },
  "spec": {
    "title": "On-call webhook",
    "integrations": [
      {
        "uid": "d9e8f7a6b5c4",
        "type": "webhook",
        "version": "1",
        "disableResolveMessage": false,
        "settings": {
          "url": "https://example.com/alerts/webhook",
          "httpMethod": "POST"
        }
      }
    ]
  }
}

Pay attention to the two name fields on Receiver:

  • metadata.name (oncall-webhook): Identifies the contact point in URL paths when you GET, PUT, PATCH, or DELETE the receiver.
  • spec.title (On-call webhook): Identifies the contact point inside alert rule notificationSettings.receiver and notification policy trees.

Step 2: Create a folder for your alert rules

Every AlertRule resource must belong to a folder (root-level placement isn’t supported). Call POST /apis/folder.grafana.app/v1/namespaces/{namespace}/folders to create a dedicated folder:

curl
curl -sS -X POST \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GRAFANA_TOKEN" \
  -d '{
    "metadata": {
      "name": "alerts-production"
    },
    "spec": {
      "title": "Production Alerts"
    }
  }' \
  "$GRAFANA_URL/apis/folder.grafana.app/v1/namespaces/$GRAFANA_NAMESPACE/folders"
gcx
gcx api "/apis/folder.grafana.app/v1/namespaces/$GRAFANA_NAMESPACE/folders" \
  -d '{
    "metadata": {
      "name": "alerts-production"
    },
    "spec": {
      "title": "Production Alerts"
    }
  }'

Grafana returns 201 Created with the Folder resource (metadata.name is alerts-production).

Step 3: Create an alert rule routed to the contact point

Save the following AlertRule definition to alert-rule.json. Notice how the fields fit together:

  • metadata.annotations["grafana.app/folder"]: Set to alerts-production (the folder’s metadata.name from Step 2).
  • spec.notificationSettings: Uses "type": "SimplifiedRouting" (required in v1beta1) and sets "receiver": "On-call webhook" to match spec.title from Step 1.
  • spec.expressions: Query A fetches CPU usage from Prometheus, expression B reduces each series to its latest value, and expression C applies the > 80 threshold with "source": true to mark it as the firing condition.
JSON
{
  "apiVersion": "rules.alerting.grafana.app/v1beta1",
  "kind": "AlertRule",
  "metadata": {
    "name": "high-cpu-usage",
    "annotations": {
      "grafana.app/folder": "alerts-production"
    }
  },
  "spec": {
    "title": "High CPU usage",
    "trigger": {
      "interval": "1m"
    },
    "for": "5m",
    "noDataState": "NoData",
    "execErrState": "Error",
    "labels": {
      "severity": "warning",
      "team": "platform"
    },
    "annotations": {
      "summary": "CPU usage is above 80% for 5 minutes"
    },
    "notificationSettings": {
      "type": "SimplifiedRouting",
      "receiver": "On-call webhook"
    },
    "expressions": {
      "A": {
        "queryType": "",
        "datasourceUID": "<PROMETHEUS_DATASOURCE_UID>",
        "relativeTimeRange": {
          "from": "5m",
          "to": "0s"
        },
        "model": {
          "expr": "100 - (avg by (instance) (rate(node_cpu_seconds_total{mode=\"idle\"}[5m])) * 100)"
        }
      },
      "B": {
        "model": {
          "type": "reduce",
          "expression": "A",
          "reducer": "last"
        }
      },
      "C": {
        "source": true,
        "model": {
          "type": "threshold",
          "expression": "B",
          "conditions": [
            {
              "evaluator": {
                "type": "gt",
                "params": [80]
              }
            }
          ]
        }
      }
    }
  }
}

Replace <PROMETHEUS_DATASOURCE_UID> with the uid of your Prometheus data source. If you want to lock the rule so it can’t be edited in the Grafana UI, also add "grafana.com/provenance": "api" inside metadata.annotations.

Create the rule with POST /apis/rules.alerting.grafana.app/v1beta1/namespaces/{namespace}/alertrules:

curl
curl -sS -X POST \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GRAFANA_TOKEN" \
  -d @alert-rule.json \
  "$GRAFANA_URL/apis/rules.alerting.grafana.app/v1beta1/namespaces/$GRAFANA_NAMESPACE/alertrules"
gcx
gcx api "/apis/rules.alerting.grafana.app/v1beta1/namespaces/$GRAFANA_NAMESPACE/alertrules" \
  -d @alert-rule.json

Grafana returns 201 Created with the saved AlertRule resource (metadata.name is high-cpu-usage).

Step 4: Inspect evaluation status, pause, and clean up

After the alert rule exists, you can read its live evaluation status, pause evaluation with a partial PATCH, or remove the resources in dependency order.

Check runtime evaluation status

Call GET /apis/rules.alerting.grafana.app/v1beta1/namespaces/{namespace}/alertrules/{name} and inspect status with jq:

curl
curl -sS \
  -H "Accept: application/json" \
  -H "Authorization: Bearer $GRAFANA_TOKEN" \
  "$GRAFANA_URL/apis/rules.alerting.grafana.app/v1beta1/namespaces/$GRAFANA_NAMESPACE/alertrules/high-cpu-usage" \
  | jq '{name: .metadata.name, title: .spec.title, health: .status.health, state: .status.state, lastEvaluationTime: .status.lastEvaluationTime}'
gcx
gcx api "/apis/rules.alerting.grafana.app/v1beta1/namespaces/$GRAFANA_NAMESPACE/alertrules/high-cpu-usage" \
  | jq '{name: .metadata.name, title: .spec.title, health: .status.health, state: .status.state, lastEvaluationTime: .status.lastEvaluationTime}'

After the first evaluation cycle completes, the response reports the rule’s health and state:

JSON
{
  "name": "high-cpu-usage",
  "title": "High CPU usage",
  "health": "OK",
  "state": "Healthy",
  "lastEvaluationTime": "2026-11-12T09:01:00Z"
}

Pause evaluation with a merge patch

Instead of sending the entire rule definition with PUT, send a PATCH request with Content-Type: application/merge-patch+json to pause evaluation during a maintenance window:

curl
curl -sS -X PATCH \
  -H "Accept: application/json" \
  -H "Content-Type: application/merge-patch+json" \
  -H "Authorization: Bearer $GRAFANA_TOKEN" \
  -d '{
    "spec": {
      "paused": true
    }
  }' \
  "$GRAFANA_URL/apis/rules.alerting.grafana.app/v1beta1/namespaces/$GRAFANA_NAMESPACE/alertrules/high-cpu-usage"
gcx
gcx api "/apis/rules.alerting.grafana.app/v1beta1/namespaces/$GRAFANA_NAMESPACE/alertrules/high-cpu-usage" \
  -X PATCH \
  -H "Content-Type: application/merge-patch+json" \
  -d '{
    "spec": {
      "paused": true
    }
  }'

Set "paused": false with the same PATCH request to resume evaluation.

Clean up resources in order

If you created these resources for testing, delete the alert rule first, then the contact point, and finally the empty folder. Deleting a contact point that is still referenced by an alert rule or deleting a non-empty folder fails with an error.

curl
curl -sS -X DELETE \
  -H "Accept: application/json" \
  -H "Authorization: Bearer $GRAFANA_TOKEN" \
  "$GRAFANA_URL/apis/rules.alerting.grafana.app/v1beta1/namespaces/$GRAFANA_NAMESPACE/alertrules/high-cpu-usage"

curl -sS -X DELETE \
  -H "Accept: application/json" \
  -H "Authorization: Bearer $GRAFANA_TOKEN" \
  "$GRAFANA_URL/apis/notifications.alerting.grafana.app/v1beta1/namespaces/$GRAFANA_NAMESPACE/receivers/oncall-webhook"

curl -sS -X DELETE \
  -H "Accept: application/json" \
  -H "Authorization: Bearer $GRAFANA_TOKEN" \
  "$GRAFANA_URL/apis/folder.grafana.app/v1/namespaces/$GRAFANA_NAMESPACE/folders/alerts-production"
gcx
gcx api "/apis/rules.alerting.grafana.app/v1beta1/namespaces/$GRAFANA_NAMESPACE/alertrules/high-cpu-usage" \
  -X DELETE

gcx api "/apis/notifications.alerting.grafana.app/v1beta1/namespaces/$GRAFANA_NAMESPACE/receivers/oncall-webhook" \
  -X DELETE

gcx api "/apis/folder.grafana.app/v1/namespaces/$GRAFANA_NAMESPACE/folders/alerts-production" \
  -X DELETE

To customize routing policies, mute timings, recording rules, or RBAC scopes, refer to the following guides: