# Provisioning alert rule through API : TypeError

**URL:** <https://community.grafana.com/t/provisioning-alert-rule-through-api-typeerror/153641>\
**Category:** Grafana\
**Tags:** query-help, api, alerting\
**Created:** [June 30, 2025, 1:21pm UTC](https://community.grafana.com/t/provisioning-alert-rule-through-api-typeerror/153641 "2025-06-30T13:21:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ambsoullier](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@ambsoullier](https://community.grafana.com/u/ambsoullier)\
**Post date:** [June 30, 2025, 1:21pm UTC](https://community.grafana.com/t/provisioning-alert-rule-through-api-typeerror/153641/1 "2025-06-30T13:21:44Z")

</div>

Hello,

After successfully uploading an alert rule. I get the error in my alert rule detail :

> [sse.dataQueryError] failed to execute query [B]: invalid: failed to decode request body: request body requires either query or AST

when I try to edit the rule :

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/f/7/f77997734d331005cbd66bf6c011b328af408663.jpeg)

Here are the rule uploaded to /api/v1/provisioning/alert-rules, also  
when I create an alert rule manually and copy paste the query it works

It seems to be an encoding error somewhere ? I noticed the query stored in grafana.db is encoding “\>” as “\u003e” ?

```auto
{
    "uid": "ceq4pkf1rturkc",
    "folderUID": "alert-folder-uid",
    "title": "La température des frigidaires sort de la plage [2-8] °C",
    "condition": "B",
    "data": [
        {
            "refId": "A",
            "relativeTimeRange": {
                "from": 900,
                "to": 0
            },
            "datasourceUid": "influxdb-uid",
            "model": {
                "datasource": {
                    "type": "influxdb",
                    "uid": "influxdb-uid"
                },
                "instant": false,
                "intervalMs": 1000,
                "maxDataPoints": 43200,
                "query": "from(bucket: \"lsb-bucket\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => \n r._measurement == \"device\" and \n r.device_type == \"fridge\" and \n r._field == \"temperature\"\n )\n |> keep(columns: [\"_time\", \"_value\", \"tag\", \"place\", \"room\"])",
                "range": true,
                "refId": "A"
            }
        },
        {
            "refId": "B",
            "relativeTimeRange": {
                "from": 900,
                "to": 0
            },
            "datasourceUid": "influxdb-uid",
            "model": {
                "conditions": [
                    {
                        "evaluator": {
                            "params": [],
                            "type": "gt"
                        },
                        "operator": {
                            "type": "and"
                        },
                        "query": {
                            "params": [
                                "A"
                            ]
                        },
                        "reducer": {
                            "params": [],
                            "type": "last"
                        },
                        "type": "query"
                    }
                ],
                "datasource": {
                    "type": "influxdb",
                    "uid": "influxdb-uid"
                },
                "expression": "A",
                "intervalMs": 1000,
                "maxDataPoints": 43200,
                "reducer": "last",
                "refId": "B",
                "type": "reduce"
            }
        },
        {
            "refId": "C",
            "relativeTimeRange": {
                "from": 900,
                "to": 0
            },
            "datasourceUid": "influxdb-uid",
            "model": {
                "conditions": [
                    {
                        "evaluator": {
                            "params": [
                                2,
                                8
                            ],
                            "type": "outside_range"
                        },
                        "operator": {
                            "type": "and"
                        },
                        "query": {
                            "params": [
                                "B"
                            ]
                        },
                        "reducer": {
                            "params": [],
                            "type": "last"
                        },
                        "type": "query"
                    }
                ],
                "datasource": {
                    "type": "influxdb",
                    "uid": "influxdb-uid"
                },
                "expression": "B",
                "intervalMs": 1000,
                "maxDataPoints": 43200,
                "refId": "B",
                "type": "threshold"
            }
        }
    ],
    "dashboardUid": "fridge-dashboard-uid",
    "panelId": 2,
    "noDataState": "NoData",
    "execErrState": "Error",
    "for": "2m",
    "annotations": {
        " __dashboardUid__": "fridge-dashboard-uid",
        " __panelId__": "2",
        "summary": "Température pour {{ $labels.tag }}.\nValeur atteinte : {{ $values.A.Value }}."
    },
    "isPaused": false,
    "notification_settings": {
        "receiver": "grafana-default-email"
    }
}

```

Grafana version : Grafana v11.3.7+security-01 (NA)

Here is the alert stored in grafana.db :

```auto
sqlite> select data from alert_rule;
[{"refId":"A","queryType":"","relativeTimeRange":{"from":900,"to":0},"datasourceUid":"influxdb-uid","model":{"datasource":{"type":"influxdb","uid":"influxdb-uid"},"instant":false,"intervalMs":1000,"maxDataPoints":43200,"query":"from(bucket: \"lsb-bucket\") |\u003e range(start: v.timeRangeStart, stop: v.timeRangeStop) |\u003e filter(fn: (r) =\u003e r._measurement == \"device\" and r.device_type == \"fridge\" and r._field == \"temperature\") |\u003e keep(columns: [\"_time\", \"_value\", \"tag\", \"place\", \"room\"])","range":true,"refId":"A"}},{"refId":"B","queryType":"","relativeTimeRange":{"from":900,"to":0},"datasourceUid":"influxdb-uid","model":{"conditions":[{"evaluator":{"params":[],"type":"gt"},"operator":{"type":"and"},"query":{"params":["A"]},"reducer":{"params":[],"type":"last"},"type":"query"}],"datasource":{"type":"influxdb","uid":"influxdb-uid"},"expression":"A","intervalMs":1000,"maxDataPoints":43200,"reducer":"last","refId":"B","type":"reduce"}},{"refId":"C","queryType":"","relativeTimeRange":{"from":900,"to":0},"datasourceUid":"influxdb-uid","model":{"conditions":[{"evaluator":{"params":[2,8],"type":"outside_range"},"operator":{"type":"and"},"query":{"params":["B"]},"reducer":{"params":[],"type":"last"},"type":"query"}],"datasource":{"type":"influxdb","uid":"influxdb-uid"},"expression":"B","intervalMs":1000,"maxDataPoints":43200,"refId":"B","type":"threshold"}}]

```
