Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Special holiday offer! You and a friend can attend FabCon with a BOGO code. Supplies are limited. Register now.
I'm trying to automate the upload of Fabric Notebooks. I cannot establish a lakehouse data source for a notebook programmatically. When using the API, it seems I need to include a .platform file, but all attempts at uploading or even downloading it fail.
This code fails with a 404 error, even when confirming the workspace_id and notebook_id are correct.
# === GET NOTEBOOK DEFINITION ===
get_url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{notebook_id}/GetDefinition?format=ipynb"
resp = requests.get(get_url, headers=headers)
resp.raise_for_status()
print("Raw API response:")
print(resp.text)
When I create a Notebook using the code at Manage and execute Fabric notebooks with public APIs - Microsoft Fabric | Microsoft Learn, the Notebook is created successfully, but the data source is not created, so when the notebook is run, it fails to process data correctly.
To fix this problem, some sources say that a .platform file is required, and I cannot seem to figure out how to include that with the Notebook creation.
Has anyone been able to both create a Notebook and set its data source programmatically? I'd love to see an example of working code.
Solved! Go to Solution.
The only reliable way that I've seen yet to automate this is to create a separate notebook that sets the connections for the other notebooks.
The only reliable way that I've seen yet to automate this is to create a separate notebook that sets the connections for the other notebooks.
Hi @stuckerj,
We would like to confirm if our community members answer resolves your query or if you need further help. If you still have any questions or need more support, please feel free to let us know. We are happy to help you.
@MJParikh ,Thanks for your prompt response
Thank you for your patience and look forward to hearing from you.
Best Regards,
Prashanth Are
MS Fabric community support
Creating a Fabric Notebook and programmatically setting its data source, particularly the lakehouse, involves some nuanced steps, especially around including the required .platform file. Based on the latest Microsoft Fabric API capabilities and community discussions, here are some insights and potential solutions:
The .platform file acts as a configuration file for integrating data sources like lakehouses with notebooks. When creating or updating notebooks via API, including this file enables programmatic association with a data source.
Creating Notebooks: Using POST requests to https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items supports uploading .ipynb files along with associated parts, but explicitly linking a data source (lakehouse) often requires this .platform file to be part of the payload.
Getting Notebook Definitions: Use GET to fetch the existing notebook's definition, which can include platform configurations.
Updating Notebook Definition: To set or change the data source, you typically need to update the notebook's definition with the .platform file, encoded in Base64, included in the parts payload.
404 Error: When attempting to upload or download the .platform file, a 404 suggests the API endpoint might be incorrect or the file isn't properly referenced within the payload [user query].
Including the .platform file: Community examples, such as GitHub discussions, show that when deploying via Terraform or direct API calls, the .platform file must be Base64 encoded and properly referenced within the parts array.
Prepare the .platform file: Create your platform configuration in JSON format, then Base64 encode it.
Include in Parts Payload: When creating or updating the notebook, include the .platform file as an inline payload similar to the .ipynb part.
Use the update-notebook-definition API: After the initial creation, update the notebook with the platform configuration to link the lakehouse.
import base64
import requests
# Sample platform configuration as JSON
platform_config = {
"lakehouse": {
"name": "MyLakehouse",
"connectionDetails": { /* connection details here */ }
}
}
# Encode to Base64
platform_payload = base64.b64encode(json.dumps(platform_config).encode('utf-8')).decode()
# Payload for updating the notebook
update_payload = {
"parts": [
{
"path": ".platform",
"payload": platform_payload,
"payloadType": "InlineBase64"
}
]
}
# API call to update the notebook definition
response = requests.post(
f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{notebook_id}/UpdateDefinition",
headers=headers,
json=update_payload
)
response.raise_for_status()Check the exact API endpoint for updating the notebook's definition; Microsoft documentation and community sources indicate both create and update endpoints support attaching the .platform part.
Ensure the payload is properly Base64 encoded and the API headers include the necessary authorization tokens.
If the API continues to return 404, review the URL endpoints, ensure the notebook exists, and confirm correct workspace and notebook IDs.
I have yet to find a payload that will work via REST API. This is consistent with the answer on another thread:
Re: REST API vs. Notebookutils Lakehouse Update Is... - Microsoft Fabric Community
It would likely be easier to create another notebook just for the purpose of setting the data source via notebookutils, which can be done directly without jumping through the hoops of creating a mysteriously formatted .platform file.
Hi @stuckerj ,
Please refer below link.
Solved: Update Notebook attached lakehouse using code - Microsoft Fabric Community
Lakehouse management API - Microsoft Fabric | Microsoft Learn
Solved: Rest Api to set default lakehouse of notebook - Microsoft Fabric Community
Solved: Re: Change default Lakehouse with notebookutils - Microsoft Fabric Community
Solved: How to set default Lakehouse in the notebook progr... - Microsoft Fabric Community
Solved: REST API TO CREATE NOTEBOOK - Microsoft Fabric Community
Solved: Re: Automate attachment of Lakehouse/data source i... - Microsoft Fabric Community
I hope this information helps. Please do let us know if you have any further queries.
Regards,
Dinesh
Hi @stuckerj ,
We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet. And, if you have any further query do let us know.
Regards,
Dinesh