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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
s_chayaphon
New Member

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 "chayaphon@abc.com" then the api can add it successfully, 

and if I have email group like "marketing@abc.com" and this email group has member of myself "chayaphon@abc.com" and other people email address the api throw error as {"error":{"code":"ItemNotFound","message":"User was not found"}}

 

Actullly I can directly add "marketing@abc.com" into workspace in website ui but for api it doesn't work.

So anyone has knowlege on this please advise.

Thanks

 

s_chayaphon_0-1683786775542.png

 

 

 

 

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)

 

 

 

 

0 REPLIES 0

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.