Forum Discussion

s_chayaphon's avatar
s_chayaphon
New Member
3 years ago

Add user to workspace by api

Hi,

 

I'm about to add user email group to the power bi worksapce by using api.

I was able to use below pyhton code well if I use normal email address, but it's doesn't work if I use email adress group which is created by AD and this email act as email group security.

 

for exmample my email is "[email protected]" then the api can add it successfully, 

and if I have email group like "[email protected]" and this email group has member of myself "[email protected]" and other people email address the api throw error as {"error":{"code":"ItemNotFound","message":"User was not found"}}

 

Actullly I can directly add "[email protected]" into workspace in website ui but for api it doesn't work.

So anyone has knowlege on this please advise.

Thanks

 

 

 

 

 

workspace_id = ' '
api_endpoint = f'https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/users'
headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + token
    }
payload = {
  "emailAddress" : " ",
  "groupUserAccessRight": "Member"
}

# Send the request to add the user to the workspace
response = requests.post(api_endpoint, headers=headers, data=json.dumps(payload))

# Check the response status code and print the result
if response.status_code == 200:
    print('user has been added to workspace : ')
else:
    print('Error adding user to the workspace: ', response.text)

 

 

 

 

No RepliesBe the first to reply