Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
Hello community,
Currently i am creating semantic layer based on SQL query and database details i have.
for this i am using below API
POST : https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/semanticModels
RequestBody :
Solved! Go to Solution.
Hi, @UmeshGoti
Based on your description, I made a working case.
First, I created a basic semantic model in Power BI desktop:
Save it as a PBIP file:
Use the following template to make a payload:
SemanticModel definition - Microsoft Fabric REST APIs | Microsoft Learn
The format should look like this:
{
"displayName": "SemanticModel 1",
"description": "A semantic model description.",
"definition": {
"parts": [....]
}
}
Next, let's process the Parts section one by one:
According to the section in the part, the content of each file in the folder is encrypted:
definition/database.tmdl
definition/model.tmdl
definition/tables/Table1.tmdl
definition/model.tmdl
definition/tables/Table.tmdl
definition.pbism
diagramLayout.json
.platform
Here I'm using Python to send requests. My script is as follows:
I'm using service principal authentication:
import requests
from azure.identity import ClientSecretCredential
class MyAPI:
def __init__(self,client_id,client_secret,tenant_id):
self.scope = 'https://analysis.windows.net/powerbi/api/.default'
self.grant_type = 'client_credentials'
self.client_id = client_id
self.client_secret = client_secret
self.tenant_id = tenant_id
def auth12 (self):
cred = ClientSecretCredential(
authority = "https://login.microsoftonline.com/",
tenant_id=self.tenant_id,
client_id=self.client_id,
client_secret=self.client_secret)
acc_token = cred.get_token(self.scope)
return acc_token.token
api = MyAPI(
client_id = 'xxxx',
client_secret = 'xxxx',
tenant_id = 'xxx'
)
workspaceId = 'xxxx'
urlPost = f"https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/semanticModels"
bodyPost = {
"displayName": "SemanticModel 1",
"description": "A semantic model description.",
"definition": {
"parts": [
{
"path": "definition/database.tmdl",
"payload": "xxxx",
"payloadType": "InlineBase64"
},
{
"path": "definition/model.tmdl",
"payload": "xxxx",
"payloadType": "InlineBase64"
},
{
"path": "definition/tables/Table.tmdl",
"payload": "xxxxx",
"payloadType": "InlineBase64"
},
{
"path": "definition.pbism",
"payload": "xxxx",
"payloadType": "InlineBase64"
},
{
"path": "diagramLayout.json",
"payload": "xxxxx",
"payloadType": "InlineBase64"
},
{
"path": ".platform",
"payload": "xxxxx",
"payloadType": "InlineBase64"
}
]
}
}
token = api.auth12()
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
res = requests.post(url=urlPost,headers=headers,json=bodyPost)
print(res.status_code)
It gets the right repercussions code and sets up the right semantic model on Power BI Service:
Best Regards
Jianpeng Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks @v-jianpeng-msft your solution works for normal report
but my requirement is to have my report connected with azure SQL Database and it's query(which should be created through above way you mentioned )
if possible can you share some hints with example if possible on that
will be very helpful to me
Thanks Again !!
@nilendraFabric very very Thanks for your quick reply
as i am using below dataSources properties and type as 'provider'
"dataSources": [
{
"name": "SqlDataSource",
"type": "provider",
"connectionDetails": {
"server": "iptools-demoserver-dev-001.database.windows.net",
"database": "mct_Sales_Raw",
"authentication": {
"type": "Basic",
"username": "techmUsercd",
"password": "next@789"
}
}
}
],
but i am getting below issue
Dataset Workload failed to import the dataset with dataset id 00000000-0000-0000-0000-000000000000. Couldn't open 'model.bim'.\nUnrecognized JSON property: connectionDetails. Check path 'model.dataSources[0].connectionDetails', line 38, position 28.
may be i am missing something in syntax standard
if possible can you please provide one basic working sample
then i can proceed further
this will me help me a lot !!
Thanks !!
Hi, @UmeshGoti
Based on your description, I made a working case.
First, I created a basic semantic model in Power BI desktop:
Save it as a PBIP file:
Use the following template to make a payload:
SemanticModel definition - Microsoft Fabric REST APIs | Microsoft Learn
The format should look like this:
{
"displayName": "SemanticModel 1",
"description": "A semantic model description.",
"definition": {
"parts": [....]
}
}
Next, let's process the Parts section one by one:
According to the section in the part, the content of each file in the folder is encrypted:
definition/database.tmdl
definition/model.tmdl
definition/tables/Table1.tmdl
definition/model.tmdl
definition/tables/Table.tmdl
definition.pbism
diagramLayout.json
.platform
Here I'm using Python to send requests. My script is as follows:
I'm using service principal authentication:
import requests
from azure.identity import ClientSecretCredential
class MyAPI:
def __init__(self,client_id,client_secret,tenant_id):
self.scope = 'https://analysis.windows.net/powerbi/api/.default'
self.grant_type = 'client_credentials'
self.client_id = client_id
self.client_secret = client_secret
self.tenant_id = tenant_id
def auth12 (self):
cred = ClientSecretCredential(
authority = "https://login.microsoftonline.com/",
tenant_id=self.tenant_id,
client_id=self.client_id,
client_secret=self.client_secret)
acc_token = cred.get_token(self.scope)
return acc_token.token
api = MyAPI(
client_id = 'xxxx',
client_secret = 'xxxx',
tenant_id = 'xxx'
)
workspaceId = 'xxxx'
urlPost = f"https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/semanticModels"
bodyPost = {
"displayName": "SemanticModel 1",
"description": "A semantic model description.",
"definition": {
"parts": [
{
"path": "definition/database.tmdl",
"payload": "xxxx",
"payloadType": "InlineBase64"
},
{
"path": "definition/model.tmdl",
"payload": "xxxx",
"payloadType": "InlineBase64"
},
{
"path": "definition/tables/Table.tmdl",
"payload": "xxxxx",
"payloadType": "InlineBase64"
},
{
"path": "definition.pbism",
"payload": "xxxx",
"payloadType": "InlineBase64"
},
{
"path": "diagramLayout.json",
"payload": "xxxxx",
"payloadType": "InlineBase64"
},
{
"path": ".platform",
"payload": "xxxxx",
"payloadType": "InlineBase64"
}
]
}
}
token = api.auth12()
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
res = requests.post(url=urlPost,headers=headers,json=bodyPost)
print(res.status_code)
It gets the right repercussions code and sets up the right semantic model on Power BI Service:
Best Regards
Jianpeng Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello @UmeshGoti
Try modifying your “SqlDataSource” definition in the semantic model JSON so that it is a provider data source rather than a structured one.
type”: “structured”
to
“type”: “provider”
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
5 | |
3 | |
3 | |
2 | |
2 |