-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathlive_sendgrid_example.py
More file actions
68 lines (61 loc) · 1.54 KB
/
live_sendgrid_example.py
File metadata and controls
68 lines (61 loc) · 1.54 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
62
63
64
65
66
67
68
import os
import json
import python_http_client
host = "https://api.sendgrid.com"
api_key = os.environ.get('SENDGRID_API_KEY')
request_headers = {
"Authorization": 'Bearer {}'.format(api_key)
}
version = 3 # we could also use client.version(3)
client = python_http_client.Client(host=host,
request_headers=request_headers,
version=version)
# GET collection
response = client.api_keys.get()
print(response.status_code)
print(response.headers)
print(response.body)
# POST
data = {
"name": "My API Key",
"scopes": [
"mail.send",
"alerts.create",
"alerts.read"
]
}
response = client.api_keys.post(request_body=data)
print(response.status_code)
print(response.headers)
print(response.body)
json_response = json.loads(response.body)
api_key_id = json_response['api_key_id']
# GET single
response = client.api_keys._(api_key_id).get()
print(response.status_code)
print(response.headers)
print(response.body)
# PATCH
data = {
"name": "A New Hope"
}
response = client.api_keys._(api_key_id).patch(request_body=data)
print(response.status_code)
print(response.headers)
print(response.body)
# PUT
data = {
"name": "A New Hope",
"scopes": [
"user.profile.read",
"user.profile.update"
]
}
response = client.api_keys._(api_key_id).put(request_body=data)
print(response.status_code)
print(response.headers)
print(response.body)
# DELETE
response = client.api_keys._(api_key_id).delete()
print(response.status_code)
print(response.headers)