350-901 · Question #83
350-901 Question #83: Real Exam Question with Answer & Explanation
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
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 = "QDAyN2I3MjMyMzY0OTY3ZDAwNjVkYjJjAXVjQzxxxxxxxx_FFS4_" webex_teams_url = "https://api.ciscospark.com/v1/" webex_teams_headers = {"Content-Type": "application/json", "Authorization": "Bearer " + webex_teams_token} user_list = ["[email protected]", "[email protected]"] def create_space(title): # 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)
Explanation
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.
Common mistakes.
- A. This option attempts to join the
user_listinto a single string and passes it, which would not correctly add individual users to the space. - C. While iterating through users, this option passes the arguments to
add_user_to_spacein the order of(space, user). Assuming theadd_user_to_spacefunction is designed to take theuseras the first argument, this order would be incorrect. - D. This option defines
userby joininguser_list, creating a single string, and then attempts to pass a non-existentusersvariable, 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.