forked from sendgrid/sendgrid-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalerts.py
More file actions
61 lines (49 loc) · 1.42 KB
/
Copy pathalerts.py
File metadata and controls
61 lines (49 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import sendgrid
import os
sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Create a new Alert #
# POST /alerts #
data = {
"email_to": "example@example.com",
"frequency": "daily",
"type": "stats_notification"
}
response = sg.client.alerts.post(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Retrieve all alerts #
# GET /alerts #
response = sg.client.alerts.get()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Update an alert #
# PATCH /alerts/{alert_id} #
data = {
"email_to": "example@example.com"
}
alert_id = "test_url_param"
response = sg.client.alerts._(alert_id).patch(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Retrieve a specific alert #
# GET /alerts/{alert_id} #
alert_id = "test_url_param"
response = sg.client.alerts._(alert_id).get()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Delete an alert #
# DELETE /alerts/{alert_id} #
alert_id = "test_url_param"
response = sg.client.alerts._(alert_id).delete()
print(response.status_code)
print(response.body)
print(response.headers)