-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistAccounts.py
executable file
·56 lines (33 loc) · 1.27 KB
/
listAccounts.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
49
50
51
52
53
#!/usr/bin/env python
import requests
import json
import hackerspace_utils as hu
authbag = hu.get_auth_bag()
url = "https://sandbox-quickbooks.api.intuit.com/v3/company/123146047051614/query"
querystring = {"minorversion":"14"}
payload="select * from Account startposition 1 maxresults 1000"
Token = authbag['token'];
headers = {
'Accept': "application/json",
'Content-Type': "application/text",
'Authorization': "Bearer "+Token,
'Cache-Control': "no-cache",
}
response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
resj = json.loads(response.text);
# import pdb; pdb.set_trace()
if("Fault" in resj):
print(json.dumps(resj,sort_keys=True,indent=4))
raise(Exception("Failed transaction.."))
#print(json.dumps(resj,sort_keys=True,indent=4))
accounts = resj['QueryResponse']['Account']
distillate = { x['Id']:
{
'id' : x['Id'],
'name' : x['Name'],
'type' : x['AccountType'],
}
for x in accounts }
# print (json.dumps(distillate,sort_keys=True,indent=4))
# print ( ("{DisplayName}".format(**x) for x in distillate.values
print( "\n".join("{id},{type},{name}".format(**item) for item in distillate.values()))