I am trying to figure out how to add to this current script below to add two fields. One i know exists and not sure on the other. Group Name and Last Date Logged in.
I just can't figure out the syntax. If anyone could help.. .would be appreciated. I took out the authentication part because I am not having an issue connecting.. .its purely the syntax of the fields i am trying to bring in. If Last Date Logged in isn't available that is fine... then i just need to add the group name to the data.
import requests
import base64
import time
def getUserList():
file = open(fileName, 'w+')
file.write('Name:GUID:Username:E ID:Team ID:DivisionID:GroupID\n')
userCount = 0
url = '/api/v2/users'
usDict = {}
jD = tokenRequest()
ahs2 = {"Authorization": "{} {}".format(jD['token_type'], jD['access_token']), "Content-Type": "application/json"}
sN = 1
resp2 = requests.get("{}{}?pageSize=20000&pageNumber={}&expand=employerInfo%2Cbiography".format(aBase, url, sN),
headers=ahs2)
pN = resp2.json()['pageCount'] + 1
while sN < pN:
resp2 = requests.get("{}{}?pageSize=20000&pageNumber={}&expand=employerInfo%2Cbiography".format(aBase, url, sN),
headers=ahs2)
data = resp2.json()['entities']
for x in data:
usLg = x['username']
usNm = x['name']
usId = x['id']
usDivisionID = x['division']['id']
if 'biography' in x['biography']:
usBg = x['biography']['biography']
else:
usBg = "NO TEAM ID"
if 'employerInfo' in x:
if 'employeeId' in x['employerInfo']:
usEd = x['employerInfo']['employeeId']
else:
usEd = 'NO EID'
else:
usEd = 'NO EID'
userCount = userCount + 1
file.write('{}:{}:{}:{}:{}:{}\n'.format(usNm, usId, usLg, usEd, usBg, usDivisionID))
sN = sN + 1
enTm = time.time()
toTm = float((enTm - stTm) / 60)
print('\n Completed {} users in {} minutes!'.format(userCount, toTm))
# Set script variables here
tBase = "https://login.usw2.pure.cloud"
aBase = "https://api.usw2.pure.cloud"
stTm = time.time()
# set File name here
fileName = 'UQL-tabbed.txt'
getUserList()