Forum Discussion
Can I update Row-level security via Rest API?
- 6 years ago
If you mean can you add users to an RLS role you defined in the pbix file, then the answer is yes,
You can get a list of the roles in a specified report with a call like
http://localhost/reports/api/v2.0/PowerBIReports(1fe72f5d-5cce-43c2-905b-fe699ed9a46a)/DataModelRoles
You would use the /DataModelRoleAssignments endpoint
eg.
http://localhost/reports/api/v2.0/PowerBIReports(1fe72f5d-5cce-43c2-905b-fe699ed9a46a)/DataModelRoleAssignments
You would do a GET request to get the all the current users in your RLS roles, then you would post back a new array with any new users added (or remove users who should no longer have access). Note that this array will replace the entire list of users.
The following would add user1 and user2 to a specific role.
[ { "GroupUserName": "user1", "DataModelRoles": [ "ef5680de-2218-4c40-b308-831ce3d108b4" ] }, { "GroupUserName": "user2", "DataModelRoles": [ "ef5680de-2218-4c40-b308-831ce3d108b4" ] } ] - 6 years ago
Power BI Report Server uses Windows Authentication by default. I know in PowerShell you can just use the -UseDefaultCredentials switch of the Invoke-RestMethod cmdlet to send the windows credentials. You will have to search for something like "python rest api windows authentication" in google or bing for information on how to do this in Python - it probably depends on what rest module you are using.
- 6 years ago
Thanks a lot.
I found the python way. I'd like to share the pkg and code with everyone.
import jsonimport requestsfrom requests_ntlm import HttpNtlmAuthurl = ''data = []oauth = HttpNtlmAuth('domain\\account','pwd')r = requests.put(url, data=json.dumps(data), auth=oauth)print (r.text)
Power BI Report Server uses Windows Authentication by default. I know in PowerShell you can just use the -UseDefaultCredentials switch of the Invoke-RestMethod cmdlet to send the windows credentials. You will have to search for something like "python rest api windows authentication" in google or bing for information on how to do this in Python - it probably depends on what rest module you are using.
Thanks a lot.
I found the python way. I'd like to share the pkg and code with everyone.