<?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: Need help to create Lakehouse programmatically using Service Principal in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4120281#M54995</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/749152"&gt;@kur83&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;Thank you for the correction and quick reply.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; You can try to use Power Automate cloud flow to automatically create a lakehouse, and here are the links to related questions, I hope you find it helpful:&lt;BR /&gt;&lt;A href="https://community.fabric.microsoft.com/t5/General-Discussion/Programmatic-Lakehouse-Shortcut-Creation-with-an-Entra-Service/m-p/3881155" target="_blank"&gt;Programmatic Lakehouse Shortcut Creation with an E... - Microsoft Fabric Community&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Leroy Lu&lt;/P&gt;</description>
    <pubDate>Tue, 27 Aug 2024 08:26:59 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-08-27T08:26:59Z</dc:date>
    <item>
      <title>Need help to create Lakehouse programmatically using Service Principal</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4109409#M54864</link>
      <description>&lt;P&gt;Need help to create Lakehouse programmatically using Service Principal&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried Fabric Rest API and it gives error as Fabric Rest API doesn't support Service Principal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rest API: &lt;A href="https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/lakehouses" target="_blank" rel="noopener"&gt;https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/lakehouses&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Documentation Link -&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/rest/api/fabric/lakehouse/items/create-lakehouse" target="_blank" rel="noopener"&gt;https://learn.microsoft.com/en-us/rest/api/fabric/lakehouse/items/create-lakehouse&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any other way to create lakehosue using service principal or Managed Identity?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2024 14:41:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4109409#M54864</guid>
      <dc:creator>kur83</dc:creator>
      <dc:date>2024-08-20T14:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to create Lakehouse programmatically using Service Principal</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4110616#M54882</link>
      <description>&lt;P&gt;Hi,&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/749152"&gt;@kur83&lt;/a&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;&lt;SPAN&gt;We believe that the main reason you have an issue with the Fabric Rest API not supporting service principals is because your administrator has not turned on the following settings for you&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vlinyulumsft_0-1724224031673.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1154519iEFB4850D4FAED1CA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vlinyulumsft_0-1724224031673.png" alt="vlinyulumsft_0-1724224031673.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;" lang="zh-CN"&gt;Here is a screenshot of the official document:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vlinyulumsft_1-1724224031674.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1154518iE0141AFA8D6300E3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vlinyulumsft_1-1724224031674.png" alt="vlinyulumsft_1-1724224031674.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;" lang="zh-CN"&gt;Here is a link to the official documentation:&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"&gt;&lt;A href="https://learn.microsoft.com/en-us/rest/api/fabric/articles/identity-support" target="_blank"&gt;&lt;SPAN&gt;Identity support for logging into the Microsoft Fabric - Microsoft Fabric REST APIs | Microsoft Learn&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;" lang="zh-CN"&gt;You may need to note that you need to enable the corresponding API and be in the fabric capacity.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vlinyulumsft_2-1724224062939.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1154520i66194EFFBC3214F8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vlinyulumsft_2-1724224062939.png" alt="vlinyulumsft_2-1724224062939.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;SPAN&gt;Of course, if you have any new ideas, you are welcome to contact us.&lt;BR /&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;Best Regards,&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;Leroy Lu&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;If this post &lt;SPAN&gt;helps&lt;/SPAN&gt;, then please consider Accept it &lt;SPAN&gt;as the solution &lt;/SPAN&gt;to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 07:07:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4110616#M54882</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-08-21T07:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to create Lakehouse programmatically using Service Principal</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4111416#M54889</link>
      <description>&lt;P&gt;Documentation states that &lt;STRONG&gt;Create Item&lt;/STRONG&gt; is not supported.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kur83_0-1724249667240.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1154743iEEEC9E13A9D0C98A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kur83_0-1724249667240.png" alt="kur83_0-1724249667240.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FYI.. We can use Service principal to create workspace and list lakehouse or list items but create item or create lakehouse gives error.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 14:15:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4111416#M54889</guid>
      <dc:creator>kur83</dc:creator>
      <dc:date>2024-08-21T14:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to create Lakehouse programmatically using Service Principal</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4120281#M54995</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/749152"&gt;@kur83&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;Thank you for the correction and quick reply.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; You can try to use Power Automate cloud flow to automatically create a lakehouse, and here are the links to related questions, I hope you find it helpful:&lt;BR /&gt;&lt;A href="https://community.fabric.microsoft.com/t5/General-Discussion/Programmatic-Lakehouse-Shortcut-Creation-with-an-Entra-Service/m-p/3881155" target="_blank"&gt;Programmatic Lakehouse Shortcut Creation with an E... - Microsoft Fabric Community&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Leroy Lu&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 08:26:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4120281#M54995</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-08-27T08:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to create Lakehouse programmatically using Service Principal</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4120957#M54998</link>
      <description>&lt;P&gt;We had "Allow Service Principal to Create and Use Profile" disabled. After enabling, it started working. Thanks for the help.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 14:35:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4120957#M54998</guid>
      <dc:creator>kur83</dc:creator>
      <dc:date>2024-08-27T14:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to create Lakehouse programmatically using Service Principal</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4192503#M56290</link>
      <description>&lt;UL&gt;&lt;LI&gt;Can you provide the rest api script you used to create a item, I having problem in creating items, get 400 bad request. Also not sure how to create or update notebooks or lakehouse. Kindly provide the script used, I have provide all mentioned permissions. Much needed help. My . Lakehouse,. Notebook,. Pipeline folders are stored in azure repo. Witj each folder containing. Platform and respective json Or. Py files. Now I want to use azure devops yaml and powershell to deploy it to uat using rest api and service principal.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Sun, 29 Sep 2024 04:51:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4192503#M56290</guid>
      <dc:creator>Devon_Rtk</dc:creator>
      <dc:date>2024-09-29T04:51:33Z</dc:date>
    </item>
    <item>
      <title>Workspace Creation, capacity assignment,  Lakehouse creation and User access - Rest API Python</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4209752#M57733</link>
      <description>&lt;P&gt;Here's the Python code for Workspace Check and Creation, Assign to Capacity and Lakehouse Creation and User access:&lt;/P&gt;&lt;P&gt;#############################################&lt;/P&gt;&lt;P&gt;# Import libraries and functions&lt;/P&gt;&lt;P&gt;import json&lt;BR /&gt;import requests&lt;BR /&gt;import datetime, time&lt;/P&gt;&lt;P&gt;from datetime import *&lt;BR /&gt;from time import *&lt;BR /&gt;from pyspark.sql.types import *&lt;BR /&gt;from pyspark.sql.functions import *&lt;/P&gt;&lt;P&gt;# Parameters&lt;BR /&gt;dest_workspacename = 'fabric_ws'&lt;BR /&gt;dest_lakehousename = 'fabric_lh'&lt;BR /&gt;capacityname = 'fabric capacity' #fabric Capacity name&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;fabric_base_url = '&lt;A href="https://api.fabric.microsoft.com/v1/" target="_blank"&gt;https://api.fabric.microsoft.com/v1/&lt;/A&gt;'&lt;BR /&gt;powerbi_base_url = '&lt;A href="https://api.powerbi.com/v1.0/myorg/groups/" target="_blank"&gt;https://api.powerbi.com/v1.0/myorg/groups/&lt;/A&gt;'&lt;/P&gt;&lt;P&gt;keyvault = '&lt;A href="https://kvl.vault.azure.net/" target="_blank"&gt;https://kvl.vault.azure.net/&lt;/A&gt;' # Keyvault Name&lt;/P&gt;&lt;P&gt;# Getting information for Tenant ID, Client ID (Service Principal) and Client Password&lt;BR /&gt;tenant_id=mssparkutils.credentials.getSecret(keyvault, 'tenant_id')&lt;BR /&gt;client_id=mssparkutils.credentials.getSecret(keyvault, 'client_id')&lt;BR /&gt;client_secret=mssparkutils.credentials.getSecret(keyvault, 'client_secret')&lt;/P&gt;&lt;P&gt;# Rest API response codes&lt;BR /&gt;http_ok_code = 200&lt;BR /&gt;http_accepted_code = 202&lt;BR /&gt;http_created_code = 201&lt;/P&gt;&lt;P&gt;access_token = None&lt;BR /&gt;token_expiration = None&lt;/P&gt;&lt;P&gt;admin_groups=[]&lt;/P&gt;&lt;P&gt;# Token Generation&lt;/P&gt;&lt;P&gt;def token_generation(client_id,client_secret,tenant_id):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; token_endpoint = f'&lt;A href="https://login.microsoftonline.com/{tenant_id}/oauth2/token" target="_blank"&gt;https://login.microsoftonline.com/{tenant_id}/oauth2/token&lt;/A&gt;'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; resource_endpoint = '&lt;A href="https://analysis.windows.net/powerbi/api" target="_blank"&gt;https://analysis.windows.net/powerbi/api&lt;/A&gt;'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; token_payload = {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 'grant_type': 'client_credentials',&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 'client_id': client_id,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 'client_secret': client_secret,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 'resource': resource_endpoint&lt;BR /&gt;&amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; response = requests.post(token_endpoint, data=token_payload)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if response.status_code == 200:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; token_data = json.loads(response.text)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; token = token_data.get('access_token')&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; access_token = f'Bearer {token}'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; expires_on = token_data.get('expires_on')&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if expires_on is not None:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; token_expiration = datetime.utcfromtimestamp(int(expires_on)) + timedelta(hours=1)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; token_expiration = None&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; access_token = None&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; token_expiration = None&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; raise requests.HTTPError(response.text)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; return access_token,token_expiration&lt;/P&gt;&lt;P&gt;if access_token is None or token_expiration is None or token_expiration &amp;lt; datetime.utcnow():&lt;BR /&gt;&amp;nbsp; &amp;nbsp; access_token, token_expiration = token_generation(client_id, client_secret, tenant_id)&lt;/P&gt;&lt;P&gt;# Workspace check and creation&lt;/P&gt;&lt;P&gt;url = fabric_base_url+"workspaces"&lt;BR /&gt;payload={}&lt;BR /&gt;headers = {'Authorization': access_token}&lt;BR /&gt;response = requests.request("GET", url, headers=headers, data=payload)&lt;BR /&gt;found = False&lt;BR /&gt;if response.status_code == http_ok_code:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; response=json.loads(response.text)["value"]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for row in response:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if row['displayName'] == dest_workspacename:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; found = True&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dest_workspaceid=row['id']&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if not found:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; payload = f'{{"displayName": "{dest_workspacename}"}}'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; headers = {'Authorization': access_token,'Content-Type': 'application/json'}&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; response = requests.request("POST", url, headers=headers, data=payload)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if response.status_code == http_ok_code or response.status_code == http_accepted_code or response.status_code == http_created_code:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dest_workspaceid = json.loads(response.text)["id"]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dest_workspaceid=None&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; raise requests.HTTPError(response.text)&lt;/P&gt;&lt;P&gt;&amp;nbsp;# Getting capacity ID and Assign Capacity to&amp;nbsp;Workspace&amp;nbsp;&lt;BR /&gt;url_capacities = fabric_base_url+"capacities"&lt;BR /&gt;payload={}&lt;BR /&gt;headers = {'Authorization': access_token}&lt;BR /&gt;response = requests.request("GET", url_capacities, headers=headers, data=payload)&lt;/P&gt;&lt;P&gt;if response.status_code == http_ok_code:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; response=json.loads(response.text)["value"]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for row in response:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if row['displayName'] == capacityname:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; found = True&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; capacityid=row['id']&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if not found:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; capacityid=None&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; raise requests.HTTPError(response)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;url_capacity = fabric_base_url+f"workspaces/{dest_workspaceid}/assignToCapacity"&lt;BR /&gt;payload = f'{{"capacityId": "{capacityid}"}}'&lt;BR /&gt;headers = {'Authorization': access_token,'Content-Type': 'application/json'}&lt;BR /&gt;response = requests.request("POST", url_capacity, headers=headers, data=payload)&lt;BR /&gt;if response.status_code == http_ok_code or response.status_code == http_accepted_code or response.status_code == http_created_code:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; print("Success!")&lt;BR /&gt;else:&lt;BR /&gt;print("failed")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; raise requests.HTTPError(response)&lt;/P&gt;&lt;P&gt;# Lakehouse check and creation&lt;BR /&gt;url_lakehouse = fabric_base_url+f"workspaces/{dest_workspaceid}/lakehouses"&lt;BR /&gt;payload={}&lt;BR /&gt;headers = {'Authorization': access_token}&lt;BR /&gt;response = requests.request("GET", url_lakehouse, headers=headers, data=payload)&lt;/P&gt;&lt;P&gt;found = False&lt;BR /&gt;if response.status_code == http_ok_code:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; response=json.loads(response.text)["value"]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for row in response:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if row['displayName'] == dest_lakehousename:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; found = True&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dest_lakehouseid=row['id']&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if not found:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; payload = f'{{"displayName": "{dest_lakehousename}"}}'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; headers = {'Authorization': access_token,'Content-Type': 'application/json'}&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; response = requests.request("POST", url_lakehouse, headers=headers, data=payload)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if response.status_code == http_ok_code or response.status_code == http_accepted_code or response.status_code == http_created_code:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dest_lakehouseid = json.loads(response.text)["id"]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dest_lakehouseid = None&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; raise requests.HTTPError(response.text)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# Getting SQL Endpoint details&lt;BR /&gt;dest_sqlendpointlink = None&lt;BR /&gt;while dest_sqlendpointlink == None or dest_sqlendpointlink == "":&lt;BR /&gt;&amp;nbsp; &amp;nbsp; sleep(30)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; url_lakehouse_details = url_lakehouse + f"/{dest_lakehouseid}"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; response = requests.request("GET", url_lakehouse_details, headers=headers, data=payload)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if response.status_code == http_ok_code or response.status_code == http_accepted_code or response.status_code == http_created_code:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dest_sqlendpointlink = json.loads(response.text)['properties']['sqlEndpointProperties']['connectionString']&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dest_sqlendpointlink = None&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; raise requests.HTTPError(response.text)&lt;/P&gt;&lt;P&gt;# Getting User details:&lt;BR /&gt;url_users = powerbi_base_url+f'{dest_workspaceid}/users'&lt;BR /&gt;headers = {'Authorization': access_token}&lt;BR /&gt;response = requests.get(url_users, headers=headers)&lt;BR /&gt;if response.status_code == 200:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; users = response.json()["value"]&lt;BR /&gt;else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; users = []&lt;BR /&gt;&amp;nbsp; &amp;nbsp; print(response.status_code)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; print("Error getting users from workspace")&lt;/P&gt;&lt;P&gt;users_dict_id = [principal['identifier'] for principal in users if principal.get('principalType') == 'Group']&lt;BR /&gt;users_dict_emailaddress = [principal['emailAddress'] for principal in users if principal.get('emailAddress', '').lower().endswith('.com')]&lt;/P&gt;&lt;P&gt;def grant_workspace_access(workspaceid,access_token,user,role):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; url = f'&lt;A href="https://api.powerbi.com/v1.0/myorg/groups/{workspaceid}/users" target="_blank"&gt;https://api.powerbi.com/v1.0/myorg/groups/{workspaceid}/users&lt;/A&gt;'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; headers = {'Authorization': access_token,'Content-Type': 'application/json'}&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if '@kpmg.com' in user.lower():&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; payload = {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "emailAddress": user,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "groupUserAccessRight": "Member"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if user == master_workspace_identity:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; payload = {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "identifier": user,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "principalType": "App",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "groupUserAccessRight": "Admin"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; payload = {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "identifier": user,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "principalType": "Group",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "groupUserAccessRight": "Admin"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; try:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; response = requests.post(url, headers=headers, data=json.dumps(payload))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; response.raise_for_status()&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if response.status_code == 200:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(f"Added '{user}'")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 'Success'&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; except &amp;nbsp;requests.exceptions.HTTPError as e:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if '404 Client Error' in to_str(e):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return to_str(e)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rs_code=404&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ct=0&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; while (rs_code !=200 | ct &amp;lt;3):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sleep(10)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; response = requests.post(url, data=payload, headers=headers)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ct+=1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(f"Failed to add '{user}'")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; raise requests.HTTPError(response)&lt;/P&gt;&lt;P&gt;found = False&lt;BR /&gt;for id in admin_groups:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; print(id)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for item in users_dict_id:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if id == item:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; found = True&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if found:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(f'{id} already has access to workspace')&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if access_token is None or token_expiration is None or token_expiration &amp;lt; datetime.utcnow():&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; access_token, token_expiration = token_generation(client_id, client_secret, tenant_id)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; message = grant_workspace_access(dest_workspaceid,access_token,id,"Admin")&lt;/P&gt;&lt;P&gt;found = False&lt;BR /&gt;for id in&amp;nbsp;team_list:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; print(id)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for item in users_dict_emailaddress:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if id.lower() == item.lower():&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; found = True&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break &amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if found:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(f' {id} already has access to workspace')&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if access_token is None or token_expiration is None or token_expiration &amp;lt; datetime.utcnow():&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; access_token, token_expiration = token_generation(client_id, client_secret, tenant_id)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; message = grant_workspace_access(dest_workspaceid,access_token,id,"Member")&lt;BR /&gt;#############################################&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/815345"&gt;@Devon_Rtk&lt;/a&gt;&amp;nbsp;- Created post on your request&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2024 17:41:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4209752#M57733</guid>
      <dc:creator>kur83</dc:creator>
      <dc:date>2024-10-01T17:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace Creation, capacity assignment,  Lakehouse creation and User access - Rest API Python</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4213631#M57734</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/749152"&gt;@kur83&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;Did these content replied to the specific thread? If that is the case, you can share the original post link here and I will help you to merge them.&lt;BR /&gt;Regards,&lt;/P&gt;
&lt;P&gt;Xiaoxin Sheng&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2024 02:40:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Need-help-to-create-Lakehouse-programmatically-using-Service/m-p/4213631#M57734</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-10-03T02:40:21Z</dc:date>
    </item>
  </channel>
</rss>

