350-901 · Question #83
Refer to the exhibit. Which snippet creates a Webex Teams space and adds the users in the variable user_list to that space? import requests import json webex_teams_token =…
The correct answer is B. space = create_space("Chatops Incident Space") for user in user_list: add_user_to_space (user, space). The correct snippet iterates through each user in the user_list and calls the add_user_to_space function for each individual, passing the user identifier and the space identifier.
Question
This creates a Webex Teams space and returns the Space IDTMTM
data = {"title": title} response = requests.post(webex_teams_url + "rooms", headers=webex_teams_headers, data=json.dumps(data)) if response.status_code == 200: content = json.loads(response.content) return content['id'] else: raise Exception('Error creating space. HTTP Error Code: {}'.format(response.status_code)) def add_user_to_space(user_space, user):This add a member to a Webex Teams space by email and returns membership IDTMTM
data = {"roomId": space, "personEmail": user} response = requests.post(webex_teams_url + "memberships", headers=webex_teams_headers, data=json.dumps(data)) if response.status_code == 200: content = json.loads(response.content) return content['id'] else: raise Exception('Error Adding {} to space. HTTP Error Code: {}'.format(user, response.status_code))Options
- Aspace = create_space("Chatops Incident Space") user = ". ".join(user_list) add_user_to_space (space)
- Bspace = create_space("Chatops Incident Space") for user in user_list: add_user_to_space (user, space)
- Cspace = create_space("Chatops Incident Space") for user in user_list: add_user_to_space (space, user)
- Dspace = create_space("Chatops Incident Space") user = ". ".join(user_list) add_user_to_space (users, space)
How the community answered
(24 responses)- A4% (1)
- B79% (19)
- C8% (2)
- D8% (2)
Why each option
The correct snippet iterates through each user in the `user_list` and calls the `add_user_to_space` function for each individual, passing the user identifier and the space identifier.
This option attempts to join the `user_list` into a single string and passes it, which would not correctly add individual users to the space.
This snippet correctly uses a `for` loop to iterate through each `user` email in the `user_list`. For each `user`, it calls the `add_user_to_space` function, passing the `user`'s email and the `space` ID, which is necessary to add each user individually to the created Webex Teams space.
While iterating through users, this option passes the arguments to `add_user_to_space` in the order of `(space, user)`. Assuming the `add_user_to_space` function is designed to take the `user` as the first argument, this order would be incorrect.
This option defines `user` by joining `user_list`, creating a single string, and then attempts to pass a non-existent `users` variable, which is both syntactically and logically incorrect for adding individual users.
Concept tested: Python iteration and function calls for API interaction
Topics
Community Discussion
No community discussion yet for this question.