-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_blaster.py
More file actions
41 lines (37 loc) · 1.28 KB
/
api_blaster.py
File metadata and controls
41 lines (37 loc) · 1.28 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
import requests
from oauth_session import create_oauth_session
# OAuth2 configuration
authorization_base_url = "https://cognito.justinsweb.com/oauth2/authorize"
token_url = "https://cognito.justinsweb.com/oauth2/token"
scope = [
"jw/admin",
]
# Create authenticated session for API calls
api_blaster = create_oauth_session(
authorization_base_url=authorization_base_url,
token_url=token_url,
scope=scope
)
# Script logic
url = "https://api.justinsweb.com/prod/echo"
data = {"message": "YOUR MESSAGE HERE"}
response = api_blaster.post(url, json=data)
try:
response.raise_for_status()
print(response.text)
except requests.HTTPError as e:
print(f"HTTP error: {e}")
print(f"Response content: {response.text}")
################################
#
# Requests Library Docs and Examples...
#
# https://requests.readthedocs.io/en/latest/user/quickstart/
# response = api_blaster.get('https://httpbin.org/get')
# response = api_blaster.post('https://httpbin.org/post', data={'key': 'value'})
# response = api_blaster.put('https://httpbin.org/put', data={'key': 'value'})
# response = api_blaster.delete('https://httpbin.org/delete')
# response = api_blaster.head('https://httpbin.org/get')
# response = api_blaster.options('https://httpbin.org/get')
#
################################