<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: REST API TO CREATE NOTEBOOK in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/REST-API-TO-CREATE-NOTEBOOK/m-p/4353512#M5941</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/233243"&gt;@jennratten&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thank you for your response. I am trying to read a ".py" &amp;amp; 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 "&lt;STRONG&gt;Language name undefined is not valid for synapse_pyspark kernel.&lt;/STRONG&gt;" when I open the notebook inside workspace. It will be very helpfull if you have any thing which I can reffer to achieve this.&lt;BR /&gt;&lt;BR /&gt;Code I use to create notebook is:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;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}");
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Jan 2025 13:54:18 GMT</pubDate>
    <dc:creator>sambhubiswal</dc:creator>
    <dc:date>2025-01-07T13:54:18Z</dc:date>
    <item>
      <title>REST API TO CREATE NOTEBOOK</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/REST-API-TO-CREATE-NOTEBOOK/m-p/4353075#M5930</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;I am trying to create a notebook in an existing workspace by reading ".py" &amp;amp; ".platform" file from my local drive using C Sharp application with REST API.&amp;nbsp;&lt;BR /&gt;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.&lt;BR /&gt;&lt;A href="https://learn.microsoft.com/en-us/rest/api/fabric/notebook/items/create-notebook?tabs=HTTP#code-try-0" target="_blank" rel="noopener"&gt;Items - Create Notebook - REST API (Notebook) | Microsoft Learn&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://learn.microsoft.com/en-us/fabric/data-engineering/notebook-public-api" target="_blank" rel="noopener"&gt;Manage and execute Fabric notebooks with public APIs - Microsoft Fabric | Microsoft Learn&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 08:45:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/REST-API-TO-CREATE-NOTEBOOK/m-p/4353075#M5930</guid>
      <dc:creator>sambhubiswal</dc:creator>
      <dc:date>2025-01-07T08:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: REST API TO CREATE NOTEBOOK</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/REST-API-TO-CREATE-NOTEBOOK/m-p/4353459#M5936</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/909173"&gt;@sambhubiswal&lt;/a&gt;&amp;nbsp;- thanks for posting.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp; Please let me know if this is not correct.&amp;nbsp; The info below applies to this scenario.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you getting any errors returned from the API call, like&amp;nbsp;InvalidItemType, ItemDisplayNameAlreadyInUse, CorruptedPayload?&amp;nbsp; These can help us figure out what might be the problem.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are a few things to check:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Verify that the definition is correctly formatted - it should include the format (such as ipynb) and the parts with the correct path, payload, and payloadType (such as InlineBase64).&lt;/LI&gt;
&lt;LI&gt;Verify that the payloads for the .py and .platform files are correctly encoded in base64.&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Here is a sample script:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;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"
      }
    ]
  }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 07 Jan 2025 13:06:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/REST-API-TO-CREATE-NOTEBOOK/m-p/4353459#M5936</guid>
      <dc:creator>jennratten</dc:creator>
      <dc:date>2025-01-07T13:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: REST API TO CREATE NOTEBOOK</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/REST-API-TO-CREATE-NOTEBOOK/m-p/4353512#M5941</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/233243"&gt;@jennratten&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thank you for your response. I am trying to read a ".py" &amp;amp; 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 "&lt;STRONG&gt;Language name undefined is not valid for synapse_pyspark kernel.&lt;/STRONG&gt;" when I open the notebook inside workspace. It will be very helpfull if you have any thing which I can reffer to achieve this.&lt;BR /&gt;&lt;BR /&gt;Code I use to create notebook is:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;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}");
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 13:54:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/REST-API-TO-CREATE-NOTEBOOK/m-p/4353512#M5941</guid>
      <dc:creator>sambhubiswal</dc:creator>
      <dc:date>2025-01-07T13:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: REST API TO CREATE NOTEBOOK</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/REST-API-TO-CREATE-NOTEBOOK/m-p/4355331#M5967</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/909173"&gt;@sambhubiswal&lt;/a&gt;&amp;nbsp;-&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp; 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.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are some references with good material:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/PowerBiDevCamp/FabricUserApiDemo" target="_self"&gt;https://github.com/PowerBiDevCamp/FabricUserApiDemo&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/dotnet/interactive/blob/main/docs/kernels-overview.md" target="_self"&gt;https://github.com/dotnet/interactive/blob/main/docs/kernels-overview.md&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/dotnet/interactive/blob/main/docs/NotebookswithJupyter.md" target="_self"&gt;https://github.com/dotnet/interactive/blob/main/docs/NotebookswithJupyter.md&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;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}");
            }
        }
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2025 13:47:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/REST-API-TO-CREATE-NOTEBOOK/m-p/4355331#M5967</guid>
      <dc:creator>jennratten</dc:creator>
      <dc:date>2025-01-08T13:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: REST API TO CREATE NOTEBOOK</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/REST-API-TO-CREATE-NOTEBOOK/m-p/4358536#M6015</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/909173"&gt;@sambhubiswal&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;Thank for reaching out in Microsoft Community Forum.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;I trust&lt;SPAN&gt;&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/233243"&gt;@jennratten&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;response is accurate and will address your issue.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;If you have any further questions or updates regarding your issue, feel free to ask, and we will look into that.&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN data-teams="true"&gt;If the Super User's answer meets your requirements, please consider marking it as the "A&lt;STRONG&gt;ccepted as&amp;nbsp; Solution"&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;Regards,&lt;BR /&gt;Pavan.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2025 09:29:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/REST-API-TO-CREATE-NOTEBOOK/m-p/4358536#M6015</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2025-01-10T09:29:14Z</dc:date>
    </item>
    <item>
      <title>Re: REST API TO CREATE NOTEBOOK</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/REST-API-TO-CREATE-NOTEBOOK/m-p/4370430#M6211</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/909173"&gt;@sambhubiswal&lt;/a&gt;,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wanted to follow up since we haven't heard back from you regarding our last response. We hope your issue has been resolved.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If the community member's answer your query, please mark it as "&lt;/SPAN&gt;&lt;STRONG&gt;Accept as Solution&lt;/STRONG&gt;&lt;SPAN&gt;" and select "&lt;/SPAN&gt;&lt;STRONG&gt;Yes&lt;/STRONG&gt;&lt;SPAN&gt;" if it was helpful.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you need any further assistance, feel free to reach out.&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Pavan.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2025 03:22:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/REST-API-TO-CREATE-NOTEBOOK/m-p/4370430#M6211</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2025-01-19T03:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: REST API TO CREATE NOTEBOOK</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/REST-API-TO-CREATE-NOTEBOOK/m-p/4375609#M6377</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/909173"&gt;@sambhubiswal&lt;/a&gt;,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wanted to follow up since we haven't heard back from you regarding our last response. We hope your issue has been resolved.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If the community member's answer your query, please mark it as "&lt;/SPAN&gt;&lt;STRONG&gt;Accept as Solution&lt;/STRONG&gt;&lt;SPAN&gt;" and select "&lt;/SPAN&gt;&lt;STRONG&gt;Yes&lt;/STRONG&gt;&lt;SPAN&gt;" if it was helpful.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you need any further assistance, feel free to reach out.&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Pavan.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 12:07:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/REST-API-TO-CREATE-NOTEBOOK/m-p/4375609#M6377</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2025-01-22T12:07:00Z</dc:date>
    </item>
  </channel>
</rss>

