Create a Service User in PrecisionLender Administration tab
import http.client
import getpass
import json
import urllib.parse
import pandas as pd
from io import StringIO
import os
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.eyJhdWQiOiJodHRwczovL3N0b3JhZ2UuYXp1cmUuY29tIiwiaXNzIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvZjA2ZDQ1OWItZDkzNS00YWQ3LWE5ZDMtYTgyMzQzYzRjOWRhLyIsImlhdCI6MTYwNjkyNTI4NiwibmJmIjoxNjA2OTI1Mjg2LCJleHAiOjE2MDY5MjkxODYsImFpbyI6IkUyUmdZUEI0S1IvZFdMSnphZFQ1Q2JQblpqNEpCd0E9IiwiYXBwaWQiOiIwN2JlNDJlYS0xY2Y2LTQ5YTYtYmIzYy1lMTVmOGU2Y2U2MTciLCJhcHBpZGFjciI6IjEiLCJpZHAiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC9mMDZkNDU5Yi1kOTM1LTRhZDctYTlkMy1hODIzNDNjNGM5ZGEvIiwib2lkIjoiNDhlYzMyMzgtYTZjZi00NTYwLWE4MjAtYzBiNjgzOGE1NGI5IiwicmgiOiIwLkFBQUFtMFZ0OERYWjEwcXAwNmdqUThUSjJ1cEN2Z2YySEtaSnV6emhYNDVzNWhkYkFBQS4iLCJzdWIiOiI0OGVjMzIzOC1hNmNmLTQ1NjAtYTg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ctYTlkMy1hODIzNDNjNGM5ZGEvIiwib2lkIjoiNDhlYzMyMzgtYTZjZi00NTYwLWE4MjAtYzBiNjgzOGE1NGI5IiwicmgiOiIwLkFBQUFtMFZ0OERYWjEwcXAwNmdqUThUSjJ1cEN2Z2YySEtaSnV6emhYNDVzNWhkYkFBQS4iLCJzdWIiOiI0OGVjMzIzOC1hNmNmLTQ1NjAtYTgyMC1jMGI2ODM4YTU0YjkiLCJ0aWQiOiJmMDZkNDU5Yi1kOTM1LTRhZDctYTlkMy1hODIzNDNjNGM5ZGEiLCJ1dGkiOiI2czdXTVhnNm9FcVFaOHQxYjJ3VUFBIiwidmVyIjoiMS4wIn0.gyGo7u3qmR2qEWnTGOC3az6BjjjB7oJkBb0Be9X6lXhZpI-egBrlymGd-mPjXtaRmArIdxG0k75b_7UkcICtiaPvtsEujUmZHXLkEtBZ8Uz7qF8pIIbQf1cBnz7Pj9Z9coBLYXg2rD9rM8YQYVEr4HR1NtvS7v1IRp1kKzDjrtGdsixsJurU7nyxLUcYDZ4tOiNW_bmM5LPKrDyXFxSdzonJFTCvG1XuPbjztOO80mhs48hpNMresi8zYM1lPyteByBOeMfBo6X6Q1kC4hpLu0d-3zIx4dcgNs0neaLM18WTyQ1hcYAyzXrXi6-URszu0M9kCQeWyuR3BPjZC72gIg
Do not forgot to URL encode the directory path!
# Path parameters
filesystem = 'datamart'
# Query Parameters
recursive = False
# Headers
headers = {
'clientid': clientid,
'authorization': "Bearer " + access_token
}
# directory
workspace = '/Workspace/Derived/'
instance_partition = "/InstancePartition=" + clientid + "/"
directory = workspace + instance_partition
encoded_directory = urllib.parse.quote_plus(directory)
conn.request("GET", "/L3/v1/workbench/" + filesystem + "?directory=" + encoded_directory + "&recursive=" + str(recursive) , headers=headers)
res = conn.getresponse()
data = res.read()
l3_paths = json.loads(data.decode("utf-8"))
l3_paths["paths"]
[{'contentLength': '0', 'etag': '0x8D808C9874BB51B', 'isDirectory': 'true', 'lastModified': 'Thu, 04 Jun 2020 20:54:52 GMT', 'name': 'Workspace/Derived/InstancePartition=a9cdadd4-1324-4a7a-842e-fe8fc9fe37f1/CoreAccountDetails'}, {'contentLength': '0', 'etag': '0x8D7BB9382C021E1', 'isDirectory': 'true', 'lastModified': 'Thu, 27 Feb 2020 14:44:12 GMT', 'name': 'Workspace/Derived/InstancePartition=a9cdadd4-1324-4a7a-842e-fe8fc9fe37f1/Pipeline-Quality'}, {'contentLength': '0', 'etag': '0x8D896DCFEDB6128', 'lastModified': 'Wed, 02 Dec 2020 16:11:58 GMT', 'name': 'Workspace/Derived/InstancePartition=a9cdadd4-1324-4a7a-842e-fe8fc9fe37f1/test.csv'}]
filename = 'test.csv'
path = workspace + instance_partition + filename
path
'/Workspace/Derived//InstancePartition=a9cdadd4-1324-4a7a-842e-fe8fc9fe37f1/test.csv'
conn.request("DELETE", "/L3/v1/workbench/" + filesystem + path + "?recursive=false", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Check if file successfully deleted
conn.request("GET", "/L3/v1/workbench/" + filesystem + "?directory=" + encoded_directory + "&recursive=" + str(recursive) , headers=headers)
res = conn.getresponse()
data = res.read()
l3_paths = json.loads(data.decode("utf-8"))
l3_paths["paths"]
[{'contentLength': '0', 'etag': '0x8D808C9874BB51B', 'isDirectory': 'true', 'lastModified': 'Thu, 04 Jun 2020 20:54:52 GMT', 'name': 'Workspace/Derived/InstancePartition=a9cdadd4-1324-4a7a-842e-fe8fc9fe37f1/CoreAccountDetails'}, {'contentLength': '0', 'etag': '0x8D7BB9382C021E1', 'isDirectory': 'true', 'lastModified': 'Thu, 27 Feb 2020 14:44:12 GMT', 'name': 'Workspace/Derived/InstancePartition=a9cdadd4-1324-4a7a-842e-fe8fc9fe37f1/Pipeline-Quality'}]