Forum Discussion
Listing files using REST API in Lakehouse
- 1 year ago
Hi munindra
The issue you’re encountering is due to the differences in API endpoints for listing tables versus files in a Microsoft Fabric Lakehouse.
For listing files in a Lakehouse, you need to use a different API endpoint. The correct approach is to use the Azure Data Lake Storage Gen2 REST API, as the Lakehouse files are stored in OneLake, which is compatible with ADLS Gen2.To list files, you should use an endpoint similar to this
You’ll need to include the appropriate authentication headers, typically using a bearer token obtained for the ‘storage’ scope.
use this approach and see
import requests
workspace_id = "your_workspace_id"
lakehouse_id = "your_lakehouse_id"
token = mssparkutils.credentials.getToken("storage")url = f"https://onelake.dfs.fabric.microsoft.com/{workspace_id}/{lakehouse_id}.lakehouse/Files?resource=filesystem&recursive=true"
headers = {"Authorization": f"Bearer {token}"}response = requests.get(url, headers=headers)
files = response.json()please accept the solution and give kudos if this is helpful.
Thanks
Nilendra