Yuka Mori on 07 Feb 2024 06:26:08
I want to create tables, populate data, and create shortcuts in the Lakehouse by simply executing Notebook code.
I want to automate the manual process of creating shortcuts using Notebook code or by using something other than Notebook.
- Comments (2)
RE: I want to create a shortcut for Lakehouse in notebook code.
As pasting code is not really possible here, I pasted the example here:https://pastebin.com/PAsinbC1
RE: I want to create a shortcut for Lakehouse in notebook code.
You can use the following code to do so:import requestsimport jsonfrom notebookutils import mssparkutilsworkspace_id = spark.conf.get("trident.workspace.id")lakehouse_item_id = mssparkutils.lakehouse.list()[0]["id"]payload = { "name": "customers", "path": "Tables", "target": { "oneLake": { "itemId": lakehouse_item_id, "path": "Files/cmk-container/silver/customers", "workspaceId": workspace_id } }}token = mssparkutils.credentials.getToken('pbi')headers = { 'Authorization': f'Bearer {token}', 'Content-type': 'application/json'}url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{lakehouse_item_id}/shortcuts"print(url)print(json.dumps(payload))response = requests.post(url, data=json.dumps(payload), headers=headers)