-
Notifications
You must be signed in to change notification settings - Fork 1
/
jira-api-user-export.py
48 lines (38 loc) · 1.15 KB
/
jira-api-user-export.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
39
40
41
42
43
44
45
46
47
48
import requests, json, csv
from requests.auth import HTTPBasicAuth
JIRA_ENDPOINT_BASE = "https://yourdomain.atlassian.net"
headers = {"Accept": "application/json"}
auth = HTTPBasicAuth("account@yourdomain.com", "yourApiToken")
CHUNK_SIZE = 1000
query = {
"startAt": -CHUNK_SIZE,
"maxResults": CHUNK_SIZE,
}
users = {}
while True:
query["startAt"] += CHUNK_SIZE
print("req", query["startAt"])
req = requests.request(
"GET",
f"{JIRA_ENDPOINT_BASE}/rest/api/3/users/search",
headers=headers,
auth=auth,
params=query,
)
data = json.loads(req.text)
if len(data) == 0:
break # Last page reached
for chunk in data:
aid = chunk["accountId"]
if aid in users.keys():
break # Last page reached
else:
users[aid] = chunk
f = open('jiraBulk.csv', 'w', encoding="UTF8")
writer = csv.writer(f, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
for user in users.values():
name = user.get("displayName", None)
id = user.get("accountId", None)
email = user.get("emailAddress", None)
writer.writerow([name, id, email])
f.close()