-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathXeroPoster.py
74 lines (53 loc) · 1.84 KB
/
XeroPoster.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Goal: Push a journal to Xero
import json
import requests
import Secrets
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
url = 'https://api.xero.com/api.xro/2.0/ManualJournals'
refreshUrl = "https://identity.xero.com/connect/token"
connectUrl ='https://api.xero.com/connections'
scope = ['offline_access', 'accounting.transactions', 'openid', 'profile', 'email', 'accounting.contacts', 'accounting.settings']
tenant = Secrets.tenant
auth = Secrets.auth
clientId = Secrets.clientId
clientSecret = Secrets.clientSecret
auth = requests.auth.HTTPBasicAuth(clientId, clientSecret)
client = BackendApplicationClient(client_id=clientId, scope=scope)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url=connectUrl, auth=auth)
print token
payload='''{ 'Narration': 'Test Journal 5 - from PYTHON',
'JournalLines': [
{
'LineAmount': 20000,
'AccountCode': '200'
},
:::
'LineAmount': -20000,
'AccountCode': '210'
}
]
}'''
headers = {
'xero-tenant-id': tenant,
'Authorization': 'Bearer ' + auth,
'Accept': 'application/json',
'Content-Type': 'application/json'
}
refreshPayload={'grant_type': 'refresh_token',
'refresh_token': 'e65ce7c0cfafd010b7be071c638706b8a489b12443632f64229e39197db4245d',
'client_id': '467E283E84B045C9B3A549B3CCD415F6',
'client_secret': 'sBq2m3GQNRwwIFVIaOyZzTF6aTEm_1WHc3s-nclllooTHXw-'
}
files=[]
refreshHeaders = {
'grant_type': 'refresh_token',
'Accept': '*/*'#,
#'Content-Type': 'application/json'
}
# Do the stuff______________________________________________________
#refreshResponse = requests.request('POST', refreshUrl, headers=refreshHeaders, data=refreshPayload, files=files)
#response = requests.request('POST', url, headers=headers, data=payload)
#print(refreshResponse.text)
#print(response.text)