I am trying to modify a DataPipeline using the API, but I only see one endpoint that allows me to change two things: name and description -> https://learn.microsoft.com/en-us/rest/api/fabric/datapipeline/items/update-data-pipeline?tabs=HTTP
With sempy_labs, I have been able to see my pipeline's definition, and I wanted to know if it is possible to modify that definition using the Fabric API -> https://semantic-link-labs.readthedocs.io/en/stable/sempy_labs.html#sempy_labs.get_data_pipeline_definition
I have been trying with this: https://learn.microsoft.com/en-us/rest/api/fabric/core/items/update-item-definition?tabs=HTTP to upload a new payload, but I only get 403 and 401 errors. I'm also not sure if this is the correct way.
I was trying doing this request for example:
import requests
item_url = f"https://api.fabric.microsoft.com/v1/workspaces/XXXXXX/items/XXXXXX"
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
body = {
"displayName": "Item's New name",
"description": "Item's New description"
}
# Use the `json` parameter to send the body as JSON data
response = requests.patch(item_url, headers=headers, json=body)
if response.status_code == 200:
print("Pipeline updated.")
else:
print(f"Error updating the item: {response.status_code} - {response.text}")
And get: Error updating the item: 400 - {"requestId":"3b4f09cc-036a-4209-b968-5879ae43bbcc","errorCode":"PrincipalTypeNotSupported","message":"The operation is not supported for the principal type"}
I had Tenant.ReadAndWriteAll scope on PowerBI services
"errorCode":"PrincipalTypeNotSupported","message":"The operation is not supported for the principal type"
I got the same error, When I used client credentials flow to update the name of dataPipeline.
This error message occurs because of Power BI REST API or fabric REST API does not fully support Service Principals for paginated report endpoints, It suggests that the API requires user-based authentication (delegated permissions) instead of a Service Principal. Refer this Blog,
To resolve the error, You need to switch to delegated type flow where user-interaction is involved.
Registered Single-Tenant Microsoft Entra ID application, To update the displayName
of item, Added Items.ReadWrite.All
API Permission and Granted Admin Consent like below:
Using delegated type, authorization_code
flow, To get code
, I ran below authorization request in browser:
https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/authorize?
client_id=<client_id>
&response_type=code
&redirect_uri=https://jwt.ms
&response_mode=query
&scope=https://analysis.windows.net/powerbi/api/.default
&state=12345
Use below Modified Python Scripting for Updating the displayName
and description
of item:
import requests
# The authorization code you generated explicitly
auth_code = "<auth-code>" # The code which you generated in browser
# Token request parameters
tenant_id = "<tenant-id>"
client_id = "<client-id>"
client_secret = "<client-secret>"
redirect_uri = "<REDIRECT_URI>" # Your registered redirect URI for your application
token_url = f"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token"
data = {
"grant_type": "authorization_code",
"client_id": client_id,
"client_secret": client_secret,
"code": auth_code,
"redirect_uri": redirect_uri,
"scope": "https://api.fabric.microsoft.com/.default"
}
# Make the request to get the access token
response = requests.post(token_url, data=data)
token_response = response.json()
# Retrieve the access token
access_token = token_response.get("access_token")
if access_token:
print("Access token retrieved successfully.")
# Use the access token to make API requests
workspace_id = "<workspace-id>"
item_id = "<item-id>"
item_url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}"
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
body = {
"displayName": "<New Name for your Item>",
"description": "<New Description for your Item"
}
# Make the PATCH request to update the item
api_response = requests.patch(item_url, headers=headers, json=body)
if api_response.status_code == 200:
print("Item updated successfully.")
else:
print(f"Error updating the item: {api_response.status_code} - {api_response.text}")
else:
print("Error retrieving access token:", token_response)
Response:
I've verified the same, By listing the details of that items and from the portal as well.
GET https://api.fabric.microsoft.com/v1/workspaces/<workspace-id>/items/<items-id>
Response:
Portal:
Reference: