Hi all,
I have been working on a use case to bulk add a specific board to “Favorites” for a list of users, which may help new users discover useful contents quicker and easier.
I am posting my script with comments to explain the workflow below for your reference. You can also run the script as a one-off task in Google Colab -- please find the link to the notebook in my Git repo.
Here is an example for add_boards_to_users(board_id: int, users_id: list)
import looker_sdk
sdk = looker_sdk.init40()
def add_boards_to_users(board_id: int, users_id: list):
""" Add a specific board to the "Favorite" contents for a list of user
Args:
board_id (int): id of a Looker board (https://company.looker.com/boards/id)
users_id (list): a list of users in the form of a native Python list
Returns: "Successfully added!" (str)
Raises: N/A (does not explicitly raise an exception); Looker SDK will raise an error.
"""
""" This statement is using sdk.board() to retrieve content_metadata_id,
which is used as a parameter for sdk.create_content_favorite()"""
content_metadata_id = sdk.board(board_id=board_id)['content_metadata_id']
"""An admin can not update the list of favorite contents for users,
`sdk.auth.login_user()` and `sdk.auth.logout()` are called to sudo as each user to call `create_content_favorite()"""
for i in users_id:
sdk.auth.login_user(i)
params = {}
params["user_id"] = i
params["content_metadata_id"] = content_metadata_id
sdk.create_content_favorite(params)
sdk.auth.logout()
return ("Successfully added!")
# Call the function
add_boards_to_users(board_id = 1, users_id = [])
The logic for `add_dashboards_to_users` is the same, except that `dashboard_id` is a string (because LookML dashboard id is a string), and we are using `sdk.dashboard()` to retrieve `content_metadata_id`. You can read the rest of the script here.
Let me know if you have questions or comments!
Cheers
Hi, is there a way to do that for all users under a specific group/role? and what if a new user joins the group?