Forum Discussion
Automate creating shortcusts
- Anonymous10 months ago
Hi AstridM ,
The 404 Not Found error occurs because your lakehouse is schema-enabled, which is the case for those created automatically by Synapse Link as well.
In schema-enabled lakehouses, tables are not available directly under the /tables endpoint, so the call fails. Instead, you should first use the GET /schemas API to list the available schemas in the lakehouse, and then call GET /schemas/{schemaName}/tables to retrieve the tables within each schema.
Once you have the table names, you can loop through them and create the shortcuts using the OneLake Shortcuts API, setting the path to Tables/<tableName> in your destination lakehouse. This approach works for both system-created and manually created schema-enabled lakehouses.
For details, please refer to the documentation: OneLake Shortcuts - REST API (Core) | Microsoft Learn
Hope this helps. Please feel free to rech out for any further questions.
Thank you .
Hi AstridM,
You are on the right track. The way to automate this at scale is:
enumerate the source lakehouse tables, and
loop over them calling the Fabric REST API to create shortcuts in your destination lakehouse under Tables/<tableName>.
Use the Lakehouse Tables API to list table names from your source lakehouse. Then POST to the OneLake Shortcuts API for each name, setting path to Tables/<tableName> and target.oneLake to the source item.
Docs: List Tables, Create Shortcut, OneLake shortcuts overview.If you prefer to do this inside a Fabric notebook, you can fetch a bearer token with mssparkutils.credentials.getToken("https://api.fabric.microsoft.com/") and call the REST APIs in a loop. Community confirmation: thread on getting tokens in notebooks
CLI confusion that creates a schema-like folder usually comes from using a path like Tables/schema/table. For lakehouse tables, point shortcuts directly to Tables/<tableName>. This places the shortcut in the Tables tree and makes it queryable in SQL Endpoint. See: Create and manage a OneLake shortcut.
Example: Python in a Fabric notebook (Not tested, but should at least get you most of the way there)
import requests
workspace_id_src="<source_ws>"
lakehouse_id_src="<source_lakehouse>"
workspace_id_dst = "<dest_ws>"
lakehouse_id_dst = "<dest_lakehouse>"
# 1) Get a bearer token scoped to Fabric API
token = mssparkutils.credentials.getToken("https://api.fabric.microsoft.com/")
# 2) List tables from source lakehouse
tables_url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id_src}/items/{lakehouse_id_src}/tables"
tables = []
next_url = tables_url
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
while next_url:
r = requests.get(next_url, headers=headers)
r.raise_for_status()
data = r.json()
tables.extend([t["name"] for t in data.get("value", [])])
next_url = data.get("@odata.nextLink")
# 3) Create shortcuts in destination lakehouse under Tables/<name>
create_url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id_dst}/items/{lakehouse_id_dst}/shortcuts"
for name in tables:
body = {
"name": name, # display name; Tables leaf drives table name in UI
"path": f"Tables/{name}",
"target": {
"oneLake": {
"workspaceId": workspace_id_src,
"itemId": lakehouse_id_src,
"path": f"Tables/{name}",
"itemType": "Lakehouse"
}
}
}
resp = requests.post(create_url, headers=headers, json=body)
if resp.status_code not in (200, 201):
print(f"Failed for {name}: {resp.status_code} {resp.text}")If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, mark this post as the solution.
Good morning, thanks, but it is not working, I tried this before, I get HTTPError: 404 Client Error: Not Found for url: api.fabric.microsoft.com/v1/workspaces/workspace_id/items/lakehouse_id/tables, from what I google it said because of the schema enable lakehouse, but I am not sure if it is that, or it is because it is a lakehouse created by the system with export to synapse link to the one lake in fabric.
- Anonymous10 months agoNot applicable
Hi AstridM ,
The 404 Not Found error occurs because your lakehouse is schema-enabled, which is the case for those created automatically by Synapse Link as well.
In schema-enabled lakehouses, tables are not available directly under the /tables endpoint, so the call fails. Instead, you should first use the GET /schemas API to list the available schemas in the lakehouse, and then call GET /schemas/{schemaName}/tables to retrieve the tables within each schema.
Once you have the table names, you can loop through them and create the shortcuts using the OneLake Shortcuts API, setting the path to Tables/<tableName> in your destination lakehouse. This approach works for both system-created and manually created schema-enabled lakehouses.
For details, please refer to the documentation: OneLake Shortcuts - REST API (Core) | Microsoft Learn
Hope this helps. Please feel free to rech out for any further questions.
Thank you .- Anonymous10 months agoNot applicable
Hi AstridM ,
I wanted to follow up on our previous suggestions. We would like to hear back from you to ensure we can assist you further.
Thank you.