Grafana 8 - Export/Import alert rules - how to?

Hello everybody,

I am working with Grafana 8 to implement alertings in our system. The workflow that I want to use is to create dashboards and alerts in our development environment, export that and use a git workflow to get that into our production environment. For Dashboards that works fine, but for the alerting system I did not find an option to export alerts in a JSON format.

I have found the a documentation for an API (Swagger Editor) and was able to make a successful GET request, but it seems there is a lot of missing information in the response.

[{'annotations': {}, 'endsAt': '2021-08-27T08:01:01.749Z', 'fingerprint': '515b1f1e733d3cc8', 'receivers': [{'name': 'grafana-default-email'}], 'startsAt': '2021-08-23T08:47:09.000Z', 'status': {'inhibitedBy': [], 'silencedBy': [], 'state': 'active'}, 'updatedAt': '2021-08-27T07:56:01.779Z', 'generatorURL': 'http://grafana.staged-by-discourse.com/alerting/Jlzduun7k/edit', 'labels': {'__alert_rule_uid__': 'Jlzduun7k', 'alertname': 'testalert'}}, {'annotations': {}, 'endsAt': '2021-08-27T08:01:01.749Z', 'fingerprint': 'd6cdb944469d5ec9', 'receivers': [{'name': 'grafana-default-email'}], 'startsAt': '2021-08-27T07:54:01.749Z', 'status': {'inhibitedBy': [], 'silencedBy': [], 'state': 'active'}, 'updatedAt': '2021-08-27T07:56:06.774Z', 'generatorURL': 'http://grafana.staged-by-discourse.com/alerting/CsGrkVVnk/edit', 'labels': {'__alert_rule_uid__': 'CsGrkVVnk', 'alertname': 'test123'}}]

I also tried to make a Post request:


requests.post(

    "http://grafana.staged-by-discourse.com/api/alertmanager/grafana/api/v2/alerts",

    json=data,

    headers=headers,

)

This did not result in an unauthorized error, nothing happened.

tldr: I tried to lot to import and exports alerts in Grafana 8, but nothing worked. Is there a way to do this and if yes, are there any working examples for this?