Skip to content

Instantly share code, notes, and snippets.

@vudngo
Last active January 14, 2021 22:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vudngo/c505d75c79e7ed1fe6592a64a790b331 to your computer and use it in GitHub Desktop.
Save vudngo/c505d75c79e7ed1fe6592a64a790b331 to your computer and use it in GitHub Desktop.
import requests
url = "https://sentry.io/api/0/projects/<ORG_SLUG_HERE>/<PROJECT_SLUG_HERE>/rules/"
payload = "{\"environment\":null,\"actionMatch\":\"all\",\"frequency\":\"30\",\"name\":\"API Alert Example\",\"conditions\":[{\"name\":\"An event is first seen\",\"id\":\"sentry.rules.conditions.first_seen_event.FirstSeenEventCondition\"},\n{\"interval\":\"1h\",\"name\":\"An event is seen more than 50 times in 1h\",\"value\":50,\"id\":\"sentry.rules.conditions.event_frequency.EventFrequencyCondition\"}],\"id\":\"412675\",\"actions\":[{\"name\":\"Send a notification (for all legacy integrations)\",\"id\":\"sentry.rules.actions.notify_event.NotifyEventAction\"},{\"channel_id\":\"CA6MX2DE2\",\"name\":\"Send a notification to the vu Slack workspace to #ember-errors and show tags [] in notification\",\"workspace\":\"1305\",\"tags\":\"\",\"id\":\"sentry.integrations.slack.notify_action.SlackNotifyServiceAction\",\"channel\":\"#ember-errors\"}]}"
headers = {
'Content-Type': "application/json",
'Authorization': "Bearer <API_TOKEN_HERE>"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment