-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_authtoken_apirequest.py
More file actions
60 lines (43 loc) · 2.22 KB
/
python_authtoken_apirequest.py
File metadata and controls
60 lines (43 loc) · 2.22 KB
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
import requests,json
import urllib3
urllib3.disable_warnings()
### Step 1 - Define auth URL, Endpoint URL, Payload and Credentials ###
# PU + OT - Replace with your tenants token URL
token_url = "https://mingle-sso.inforcloudsuite.com:443/<< REPLACE WITH YOUR TENANT >>/as/token.oauth2"
# Endpoint URL - Can get from swagger documentation in IONAPI - Replace with your tenants API URL
test_api_url = "https://mingle-ionapi.inforcloudsuite.com/<< REPLACE WITH YOUR TENANT >>/SX/rest/serviceinterface/proxy/FetchWhere"
# IONAPI Request - Replace payload with your own request
payload = """{
"CompanyNumber": << YOUR CONO >>,
"Operator": "<< YOUR SASO USERID >>",
"TableName": "<< TABLE TO QUERY >>",
"WhereClause": "",
"BatchSize": 0,
"RestartRowID": ""
}"""
#SAAK
saak_user = "<< SAAK value from .ionapi >>"
#SASK
sask_password = "<< SASK value from .ionapi >>"
#CI
client_id = '<< CI value from .ionapi >>'
#CS
client_secret = '<< CS value from .ionapi >>'
### ____________________________________________________________________________________ ###
### Step 2 - single call with resource owner credentials in the body and client credentials as the basic auth header ###
data = {
'grant_type': 'password',
'username': saak_user,
'password': sask_password
}
access_token_response = requests.post(token_url,
data=data, verify=False, allow_redirects=False,
auth=(client_id, client_secret))
tokens = json.loads(access_token_response.text)
print ("access token: " + tokens['access_token'])
### ____________________________________________________________________________________ ###
### Step 3 - now we can use the access_token to make as many calls as we want until token expires. ###
api_call_headers = {'Authorization': 'Bearer ' + tokens['access_token']}
api_call_response = requests.request("POST", test_api_url, headers=api_call_headers, data = payload, verify=False)
print (api_call_response.text.encode('utf8'))
### ____________________________________________________________________________________ ###