nerdexam
Cisco

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.

Using APIs

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)

How the community answered

(24 responses)
  • A
    4% (1)
  • B
    79% (19)
  • C
    8% (2)
  • D
    8% (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.

Aspace = create_space("Chatops Incident Space") user = ". ".join(user_list) add_user_to_space (space)

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.

Bspace = create_space("Chatops Incident Space") for user in user_list: add_user_to_space (user, space)Correct

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.

Cspace = create_space("Chatops Incident Space") for user in user_list: add_user_to_space (space, user)

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.

Dspace = create_space("Chatops Incident Space") user = ". ".join(user_list) add_user_to_space (users, space)

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

#Python Loops#Function Calls#Webex Teams API#API Integration

Community Discussion

No community discussion yet for this question.

Full 350-901 Practice