-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNB_Add_Users_Orphaned_Pipelines
37 lines (33 loc) · 1.34 KB
/
NB_Add_Users_Orphaned_Pipelines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import sempy.fabric as fabric
import pandas as pd
PBI_Rest_API = fabric.PowerBIRestClient()
try:
url = f'/v1.0/myorg/admin/pipelines'
# print(url)
deployment_pipelines_df = PBI_Rest_API.get(url).json()['value']
deployment_pipelines_df = pd.json_normalize(deployment_pipelines_df)
deployment_pipelines_df = pd.DataFrame(deployment_pipelines_df)
except Exception as e:
print(e)
display(deployment_pipelines_df)
# Iterate over the DataFrame rows
for index, row in deployment_pipelines_df.iterrows():
Pipeline_Name = row['displayName']
pipelineId = row['id']
print("-" * 50)
print(f"Processing Deployment Pipeline: {Pipeline_Name} (ID: {pipelineId})")
# Add user to the deployment pipeline
try:
add_user_url = f'/v1.0/myorg/admin/pipelines/{pipelineId}/users'
user_data = {
"identifier": "[email protected]",
"accessRight": "Admin",
"principalType": "User"
}
response = PBI_Rest_API.post(add_user_url, json=user_data)
if response.status_code == 200:
print(f"User added to pipeline {Pipeline_Name} successfully.")
else:
print(f"Failed to add user to pipeline {Pipeline_Name}. Status code: {response.status_code}")
except Exception as e:
print(f"Error adding user to pipeline {Pipeline_Name}: {str(e)}")