Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us at FabCon Vienna from September 15-18, 2025, for the ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM. Get registered
Hi Team,
I am trying to create a notebook in an existing workspace by reading ".py" & ".platform" file from my local drive using C Sharp application with REST API.
I use the REST API call mentioned in the document below, but unfortunatly, It's not working. Although I am able to create notebook without defination but that notbook is not getting open from workspace, Moreover, I am unable to create a notebook with defination. Kindly help.
Items - Create Notebook - REST API (Notebook) | Microsoft Learn
Manage and execute Fabric notebooks with public APIs - Microsoft Fabric | Microsoft Learn
Solved! Go to Solution.
Hello @sambhubiswal - thanks for posting.
Based on your description, I believe you are able to create the notebook object in the workspace but the notebook definition is not included in it so it doesn't work. Please let me know if this is not correct. The info below applies to this scenario.
Are you getting any errors returned from the API call, like InvalidItemType, ItemDisplayNameAlreadyInUse, CorruptedPayload? These can help us figure out what might be the problem.
Here are a few things to check:
Here is a sample script:
POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/notebooks
{
"displayName": "Notebook 1",
"description": "A notebook description",
"definition": {
"format": "ipynb",
"parts": [
{
"path": "notebook-content.py",
"payload": "Base64EncodedContent",
"payloadType": "InlineBase64"
},
{
"path": ".platform",
"payload": "Base64EncodedContent",
"payloadType": "InlineBase64"
}
]
}
}
If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.
Proud to be a Microsoft Fabric Super User
Hi @jennratten ,
Thank you for your response. I am trying to read a ".py" & a ".platform" file from my local drive, converting those contents to base64 encoding and using those as payload to create the same notebook inside a workspace using REST API call. For my testing purpose, I am using below code to create a sample notebook. Although the notebook created successfully, but it's throwing error "Language name undefined is not valid for synapse_pyspark kernel." when I open the notebook inside workspace. It will be very helpfull if you have any thing which I can reffer to achieve this.
Code I use to create notebook is:
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace NotebookCreation
{
class Program
{
static async Task Main(string[] args)
{
string baseUrl = $"https://api.fabric.microsoft.com/v1/workspaces/{WorkspaceID}/notebooks";
var authService = new AuthService();
string apiKey = await authService.GetAccessTokenForFabric();
var notebookName = "Notebook_Test";
var notebookDescription = "A notebook description";
var notebookContent = @"
{
""cells"": [],
""metadata"": {},
""nbformat"": 4,
""nbformat_minor"": 4
}";
var notebookPayload = Convert.ToBase64String(Encoding.UTF8.GetBytes(notebookContent));
var requestPayload = new
{
displayName = notebookName,
description = notebookDescription,
definition = new
{
format = "ipynb",
parts = new[]
{
new {
path = "notebook-content.ipynb",
payloadType = "InlineBase64",
payload = notebookPayload
}
}
},
kernelSpec = new
{
name = "synapse_pyspark",
language = "python"
}
};
var jsonPayload = Newtonsoft.Json.JsonConvert.SerializeObject(requestPayload);
using var client = new HttpClient();
client.BaseAddress = new Uri(baseUrl);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
try
{
var response = await client.PostAsync(baseUrl, content);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("Notebook created successfully.");
}
else
{
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {response.StatusCode}, {responseBody}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Exception occurred: {ex.Message}");
}
}
}
}
Hi @sambhubiswal,
I wanted to follow up since we haven't heard back from you regarding our last response. We hope your issue has been resolved.
If the community member's answer your query, please mark it as "Accept as Solution" and select "Yes" if it was helpful.
If you need any further assistance, feel free to reach out.
Thank you,
Pavan.
Hi @sambhubiswal,
I wanted to follow up since we haven't heard back from you regarding our last response. We hope your issue has been resolved.
If the community member's answer your query, please mark it as "Accept as Solution" and select "Yes" if it was helpful.
If you need any further assistance, feel free to reach out.
Thank you,
Pavan.
Hi @sambhubiswal,
Thank for reaching out in Microsoft Community Forum.
I trust @jennratten response is accurate and will address your issue.
If you have any further questions or updates regarding your issue, feel free to ask, and we will look into that.
If the Super User's answer meets your requirements, please consider marking it as the "Accepted as Solution"
Regards,
Pavan.
Hello @sambhubiswal - thanks for posting.
Based on your description, I believe you are able to create the notebook object in the workspace but the notebook definition is not included in it so it doesn't work. Please let me know if this is not correct. The info below applies to this scenario.
Are you getting any errors returned from the API call, like InvalidItemType, ItemDisplayNameAlreadyInUse, CorruptedPayload? These can help us figure out what might be the problem.
Here are a few things to check:
Here is a sample script:
POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/notebooks
{
"displayName": "Notebook 1",
"description": "A notebook description",
"definition": {
"format": "ipynb",
"parts": [
{
"path": "notebook-content.py",
"payload": "Base64EncodedContent",
"payloadType": "InlineBase64"
},
{
"path": ".platform",
"payload": "Base64EncodedContent",
"payloadType": "InlineBase64"
}
]
}
}
If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.
Proud to be a Microsoft Fabric Super User
Hi @jennratten ,
Thank you for your response. I am trying to read a ".py" & a ".platform" file from my local drive, converting those contents to base64 encoding and using those as payload to create the same notebook inside a workspace using REST API call. For my testing purpose, I am using below code to create a sample notebook. Although the notebook created successfully, but it's throwing error "Language name undefined is not valid for synapse_pyspark kernel." when I open the notebook inside workspace. It will be very helpfull if you have any thing which I can reffer to achieve this.
Code I use to create notebook is:
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace NotebookCreation
{
class Program
{
static async Task Main(string[] args)
{
string baseUrl = $"https://api.fabric.microsoft.com/v1/workspaces/{WorkspaceID}/notebooks";
var authService = new AuthService();
string apiKey = await authService.GetAccessTokenForFabric();
var notebookName = "Notebook_Test";
var notebookDescription = "A notebook description";
var notebookContent = @"
{
""cells"": [],
""metadata"": {},
""nbformat"": 4,
""nbformat_minor"": 4
}";
var notebookPayload = Convert.ToBase64String(Encoding.UTF8.GetBytes(notebookContent));
var requestPayload = new
{
displayName = notebookName,
description = notebookDescription,
definition = new
{
format = "ipynb",
parts = new[]
{
new {
path = "notebook-content.ipynb",
payloadType = "InlineBase64",
payload = notebookPayload
}
}
},
kernelSpec = new
{
name = "synapse_pyspark",
language = "python"
}
};
var jsonPayload = Newtonsoft.Json.JsonConvert.SerializeObject(requestPayload);
using var client = new HttpClient();
client.BaseAddress = new Uri(baseUrl);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
try
{
var response = await client.PostAsync(baseUrl, content);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("Notebook created successfully.");
}
else
{
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {response.StatusCode}, {responseBody}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Exception occurred: {ex.Message}");
}
}
}
}
Hi @sambhubiswal -
Based on the error message it sounds like the language property might needs to be updated in the script. Please try the new script below. You had the kernel spec included in the payload but it may need to be included in the notebook content as well with the properties defined as metadata.
Here are some references with good material:
https://github.com/PowerBiDevCamp/FabricUserApiDemo
https://github.com/dotnet/interactive/blob/main/docs/kernels-overview.md
https://github.com/dotnet/interactive/blob/main/docs/NotebookswithJupyter.md
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace NotebookCreation
{
class Program
{
static async Task Main(string[] args)
{
string baseUrl = $"https://api.fabric.microsoft.com/v1/workspaces/{WorkspaceID}/notebooks";
var authService = new AuthService();
string apiKey = await authService.GetAccessTokenForFabric();
var notebookName = "Notebook_Test";
var notebookDescription = "A notebook description";
var notebookContent = @"
{
""cells"": [],
""metadata"": {
""kernelspec"": {
""name"": ""synapse_pyspark"",
""language"": ""python""
}
},
""nbformat"": 4,
""nbformat_minor"": 4
}";
var notebookPayload = Convert.ToBase64String(Encoding.UTF8.GetBytes(notebookContent));
var requestPayload = new
{
displayName = notebookName,
description = notebookDescription,
definition = new
{
format = "ipynb",
parts = new[]
{
new {
path = "notebook-content.ipynb",
payloadType = "InlineBase64",
payload = notebookPayload
}
}
},
kernelSpec = new
{
name = "synapse_pyspark",
language = "python"
}
};
var jsonPayload = Newtonsoft.Json.JsonConvert.SerializeObject(requestPayload);
using var client = new HttpClient();
client.BaseAddress = new Uri(baseUrl);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
try
{
var response = await client.PostAsync(baseUrl, content);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("Notebook created successfully.");
}
else
{
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {response.StatusCode}, {responseBody}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Exception occurred: {ex.Message}");
}
}
}
}
If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.
Proud to be a Microsoft Fabric Super User
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Fabric update to learn about new features.