-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_r.py
38 lines (30 loc) · 1.2 KB
/
test_r.py
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
import r
import json
# Set these:
with open('okta.yaml') as f: # in JSON format: {"okta":{"client":{"orgUrl":"...","token":"..."}}}
config = json.load(f)['okta']['client']
base_url = config['orgUrl'] # eg 'https://gsroka.oktapreview.com'
group_id = '...'
r.headers.update({
'Authorization': 'SSWS ' + config['token'],
'Accept': 'application/json'
})
res = r.get(f'{base_url}/api/v1/users/me')
me = res.json
user_id = me['id']
print(me['profile']['login'], me['profile']['title'], res.headers['x-rate-limit-remaining'])
# Pagination.
url = r.url(f'{base_url}/api/v1/users', filter='profile.lastName eq "Doe"', limit=2)
while url:
res = r.get(url)
print(len(res.json), url, res.headers['x-rate-limit-remaining'])
for user in res.json:
print(user['profile']['login'])
url = res.next_url
res = r.post(f'{base_url}/api/v1/users/{user_id}', {'profile': {'title': 'technoking'}})
me = res.json
print(me['profile']['title'], res.headers['x-rate-limit-remaining'])
res = r.put(f'{base_url}/api/v1/groups/{group_id}/users/{user_id}')
print(res.headers['x-rate-limit-remaining'])
res = r.delete(f'{base_url}/api/v1/groups/{group_id}/users/{user_id}')
print(res.headers['x-rate-limit-remaining'])