FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-http-client/examples/live_sendgrid_example.py at master · CodingSta/python-http-client · GitHub
CodingSta
/
python-http-client
Public
forked from
sendgrid/python-http-client
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-http-client
/
examples
/
live_sendgrid_example.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
68 lines (61 loc) · 1.54 KB
Breadcrumbs
python-http-client
/
examples
/
live_sendgrid_example.py
Copy path
File metadata and controls
68 lines (61 loc) · 1.54 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
)
Back
|
FazBrowse Home
|
New Git URL