Create a Service User in PrecisionLender Administration tab
import http.client
import getpass
import json
clientid = "a9cdadd4-1324-4a7a-842e-fe8fc9fe37f1"
username = "L3_Workbench_Service_User"
password = getpass.getpass()
········
Connect to L3 Workbench as Service User
conn = http.client.HTTPSConnection("api.precisionlender.com")
headers = {
'clientid': clientid,
'username': username,
'password': password
}
conn.request("POST", "/L3/v1/workbench/auth", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
{"token_type":"Bearer","expires_in":3599,"ext_expires_in":3599,"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImtnMkxZczJUMENUaklmajRydDZKSXluZW4zOCIsImtpZCI6ImtnMkxZczJUMENUaklmajRydDZKSXluZW4zOCJ9.eyJhdWQiOiJodHRwczovL3N0b3JhZ2UuYXp1cmUuY29tIiwiaXNzIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvZjA2ZDQ1OWItZDkzNS00YWQ3LWE5ZDMtYTgyMzQzYzRjOWRhLyIsImlhdCI6MTYwNjkyNDc2NSwibmJmIjoxNjA2OTI0NzY1LCJleHAiOjE2MDY5Mjg2NjUsImFpbyI6IkUyUmdZRGhrMVA2YWkwR2UvYWpiTFRrZlU4TktBQT09IiwiYXBwaWQiOiIwN2JlNDJlYS0xY2Y2LTQ5YTYtYmIzYy1lMTVmOGU2Y2U2MTciLCJhcHBpZGFjciI6IjEiLCJpZHAiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC9mMDZkNDU5Yi1kOTM1LTRhZDctYTlkMy1hODIzNDNjNGM5ZGEvIiwib2lkIjoiNDhlYzMyMzgtYTZjZi00NTYwLWE4MjAtYzBiNjgzOGE1NGI5IiwicmgiOiIwLkFBQUFtMFZ0OERYWjEwcXAwNmdqUThUSjJ1cEN2Z2YySEtaSnV6emhYNDVzNWhkYkFBQS4iLCJzdWIiOiI0OGVjMzIzOC1hNmNmLTQ1NjAtYTgyMC1jMGI2ODM4YTU0YjkiLCJ0aW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EvIiwib2lkIjoiNDhlYzMyMzgtYTZjZi00NTYwLWE4MjAtYzBiNjgzOGE1NGI5IiwicmgiOiIwLkFBQUFtMFZ0OERYWjEwcXAwNmdqUThUSjJ1cEN2Z2YySEtaSnV6emhYNDVzNWhkYkFBQS4iLCJzdWIiOiI0OGVjMzIzOC1hNmNmLTQ1NjAtYTgyMC1jMGI2ODM4YTU0YjkiLCJ0aWQiOiJmMDZkNDU5Yi1kOTM1LTRhZDctYTlkMy1hODIzNDNjNGM5ZGEiLCJ1dGkiOiJOT2pZUnhrWmhVeUNmRzduaGhNUkFBIiwidmVyIjoiMS4wIn0.MtytH7xDLHAVZCTvXhr23-PMEU6l28fDUJ4pKLPbmyy9FXiYABxV_gyNUikCQZCRWIi4S6EbNrVhqtUwYae1WCq7EamfpGP-uAyilxbzTx5u3E-xAyVtCZ6-IdXkPmAmIEQKbo6TVCCDXGXh4mlLgcNjlInLxIMFV2nLSRaVNkywfzTb0Q3d2kqT1JomNzeqgmZw2z-9uFDbzAEjtOuKhwlbdnWZ90s-K9OwPxqo_of9hQ-RIRPnvI-P3Xe0vmpE9dYngd5TpVn2iBAJ8CY_IaJTBiyk6ilJJGS7fID8kCoNbHdwdEZkPeevpIverCA-BDVBPYP0VOZVyZLQ2ZaXLw
# Path parameters
filesystem = 'datamart'
# Query Parameters
recursive = False
headers = {
'clientid': clientid,
'authorization': "Bearer " + access_token
}
conn.request("GET", "/L3/v1/workbench/" + filesystem + "?recursive=" + str(recursive), headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
{"paths":[{"etag":"0x8D7F77FED85F5A1","isDirectory":"true","lastModified":"Wed, 13 May 2020 20:55:11 GMT","name":"ClientUploadedFiles"},{"etag":"0x8D7F77F5BEB00B4","isDirectory":"true","lastModified":"Wed, 13 May 2020 20:51:07 GMT","name":"L3"},{"contentLength":"0","etag":"0x8D758C3F213E9F6","isDirectory":"true","lastModified":"Thu, 24 Oct 2019 20:51:29 GMT","name":"Workspace"}]}
l3_workbench_paths = json.loads(data.decode("utf-8"))
l3_workbench_paths["paths"]
[{'etag': '0x8D7F77FED85F5A1', 'isDirectory': 'true', 'lastModified': 'Wed, 13 May 2020 20:55:11 GMT', 'name': 'ClientUploadedFiles'}, {'etag': '0x8D7F77F5BEB00B4', 'isDirectory': 'true', 'lastModified': 'Wed, 13 May 2020 20:51:07 GMT', 'name': 'L3'}, {'contentLength': '0', 'etag': '0x8D758C3F213E9F6', 'isDirectory': 'true', 'lastModified': 'Thu, 24 Oct 2019 20:51:29 GMT', 'name': 'Workspace'}]
[x["name"] for x in l3_workbench_paths["paths"]]
['ClientUploadedFiles', 'L3', 'Workspace']
# Query parameters
directory = "L3"
conn.request("GET", "/L3/v1/workbench/" + filesystem + "?directory=" + directory + "&recursive=" + str(recursive) , headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
{"paths":[{"etag":"0x8D7F77F5BEEAC54","isDirectory":"true","lastModified":"Wed, 13 May 2020 20:51:07 GMT","name":"L3/v1.0"}]}
l3_paths = json.loads(data.decode("utf-8"))
l3_paths["paths"][0]["name"]
'L3/v1.0'
# Query parameters
directory = "L3/v1.0"
conn.request("GET", "/L3/v1/workbench/" + filesystem + "?directory=" + directory + "&recursive=" + str(recursive) , headers=headers)
res = conn.getresponse()
data = res.read()
l3_paths = json.loads(data.decode("utf-8"))
l3_paths["paths"]
[{'etag': '0x8D7F7C623EB6789', 'isDirectory': 'true', 'lastModified': 'Thu, 14 May 2020 05:17:47 GMT', 'name': 'L3/v1.0/Derived'}, {'etag': '0x8D7F77F5BEF54D6', 'isDirectory': 'true', 'lastModified': 'Wed, 13 May 2020 20:51:07 GMT', 'name': 'L3/v1.0/Documentation'}, {'etag': '0x8D7F77FB2AAEF0B', 'isDirectory': 'true', 'lastModified': 'Wed, 13 May 2020 20:53:32 GMT', 'name': 'L3/v1.0/Primary'}]
[x["name"] for x in l3_paths["paths"]]
['L3/v1.0/Derived', 'L3/v1.0/Documentation', 'L3/v1.0/Primary']