-
Notifications
You must be signed in to change notification settings - Fork 0
/
Accounts.py
41 lines (32 loc) · 1.44 KB
/
Accounts.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
import requests
apiKey = 'GaS6ZkPffGZOxGZBAThMjnt9yyn9dZ28'
baseUrl = 'https://alpha-api.usbank.com/innovations/v1'
header = {'apiKey': apiKey}
url = 'https://alpha-api.usbank.com/innovations/v1/users'
response = requests.get(url, headers=header).json()['UserList']
listOfLPIs = []
for item in response:
listOfLPIs.append(item['LegalParticipantIdentifier'])
def getNamesandIdentifiers(LPIList, baseUrl, header):
namesAndIdentifiers = {}
for LPI in LPIList:
allAccountsUrl = baseUrl + '/user/accounts'
params = {'LegalParticipantIdentifier': LPI}
AADL = requests.post(allAccountsUrl, data=params, headers=header).json()['AccessibleAccountDetailList']
pi = AADL[0]['PrimaryIdentifier']
pc = AADL[0]['ProductCode']
oci = AADL[0]['OperatingCompanyIdentifier']
data = {'PrimaryIdentifier': pi,
'ProductCode': pc,
'OperatingCompanyIdentifier': oci}
accountDetailsUrl = baseUrl + '/account/details'
accountDetails = requests.post(accountDetailsUrl, data=data, headers=header).json()
detail = accountDetails['Account']['AccountDetail']
try:
name = detail['AddressAndTitle']['AccountTitle']
print(name)
except KeyError:
name = 'Unknown Name ' + str(LPIList.index(LPI) + 1)
namesAndIdentifiers[name] = LPI
return namesAndIdentifiers
getNamesandIdentifiers(listOfLPIs, baseUrl, header)