Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
santh00
Frequent Visitor

Automate the notebook using power automate

I have to automate the notebook using power automate of Invoke HTTP request used the fabric api POST https://api.fabric.microsoft.com/v1/workspaces/{{WORKSPACE_ID}}/items/{{ARTIFACT_ID}}/jobs/instances... and body is {
"executionData":{}
} i ended up having bad request error and I register an app in azure and get the client id client secret and tested using the below code I have the error of Error: 401 - {"requestId":"978734ec-410d-40ae-8a0b-faaf5938e6b5","errorCode":"Unauthorized","message":"The caller is not authenticated to access this resource"} for the below code how to overcome this issue

import requests
import json

# Step 1: Get Access Token
tenant_id = 'your_tenant_id'
client_id = 'your_client_id'
client_secret = 'your_client_secret'
scope = 'https://api.fabric.microsoft.com/.default'
grant_type = 'client_credentials'

token_url = f'https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token'
token_headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
token_body = {
'client_id': client_id,
'client_secret': client_secret,
'scope': scope,
'grant_type': grant_type
}

token_response = requests.post(token_url, headers=token_headers, data=token_body)

if token_response.status_code == 200:
access_token = token_response.json().get('access_token')
print("Access token retrieved successfully.")
else:
print(f"Error: {token_response.status_code} - {token_response.text}")
exit()

# Step 2: Execute Notebook
url = "https://api.fabric.microsoft.com/v1/workspaces/4a909421-5f1d-4bab-b83a-f6319ef0f9df/items/12914089-c..."

headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}

data = {
"executionData": {
# Include necessary execution parameters here
"param1": "value1",
"param2": "value2"
}
}

response = requests.post(url, headers=headers, data=json.dumps(data))

if response.status_code == 200:
print("Notebook executed successfully.")
else:
print(f"Error: {response.status_code} - {response.text}")

3 REPLIES 3
Anonymous
Not applicable
Anonymous
Not applicable

Hello @santh00 ,

We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet.
Otherwise, will respond back with the more details and we will try to help .

Anonymous
Not applicable

Hi @santh00 ,

We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet.
Otherwise, will respond back with the more details and we will try to help .

Helpful resources

Announcements
Fabric July 2025 Monthly Update Carousel

Fabric Monthly Update - July 2025

Check out the July 2025 Fabric update to learn about new features.

July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.