nerdexam
Cisco

300-835 · Question #22

Drag and drop the code snippets into the correct order to create a Python Webex Teams REST API script that performs this sequence of tasks: create a Space, add a user to the Space, post the word "test

Webex Teams REST API Script - Explanation Overall Goal The script automates three sequential actions against the Webex Teams (now "Webex") REST API: create a collaboration space, invite a member, then send a message. The correct order is dictated by data dependencies - each step

Cisco Webex API

Question

Drag and drop the code snippets into the correct order to create a Python Webex Teams REST API script that performs this sequence of tasks: create a Space, add a user to the Space, post the word "test" in the Space. Assume that the Python "requests" module has already been imported.

Explanation

Webex Teams REST API Script - Explanation

Overall Goal

The script automates three sequential actions against the Webex Teams (now "Webex") REST API: create a collaboration space, invite a member, then send a message. The correct order is dictated by data dependencies - each step produces an ID that the next step requires.


The Correct Order and Why

Step 1 - Create the Space

r = requests.post('https://webexapis.com/v1/rooms',
                  json={'title': 'My Space'},
                  headers={'Authorization': 'Bearer <token>'})
roomId = r.json()['id']

Why first: The Space must exist before anything can happen inside it. More importantly, the API response returns a roomId - a unique identifier that both subsequent steps require. Without this call, you have no target to add users to or post messages in.

If skipped: Steps 2 and 3 have no roomId to reference, so both would fail with a 404 or missing-parameter error.


Step 2 - Add a User to the Space

requests.post('https://webexapis.com/v1/memberships',
              json={'roomId': roomId, 'personEmail': '[email protected]'},
              headers={'Authorization': 'Bearer <token>'})

Why second: You need the roomId from Step 1. This call grants the target user membership in the space so they can see the message posted in Step 3. The /memberships endpoint links a person (by email) to a room (by ID).

If skipped: The message is posted, but the intended user was never invited and cannot see it - defeating the purpose.

If done after Step 3: Technically the API would allow it, but the user would miss the message unless they scroll back - logically incorrect for most use cases, and exam questions treat this order as wrong.


Step 3 - Post a Message in the Space

requests.post('https://webexapis.com/v1/messages',
              json={'roomId': roomId, 'text': 'test'},
              headers={'Authorization': 'Bearer <token>'})

Why last: Again requires roomId from Step 1. The room and membership must already exist. This call sends the string "test" to the /messages endpoint, targeting the room by ID.

If done before Step 2: The message succeeds, but the added user won't see it in their notification feed (depending on platform behavior) - wrong sequence for the stated goal.


Key Dependency Chain

POST /rooms  →  roomId  →  POST /memberships (uses roomId)
                        →  POST /messages    (uses roomId)

roomId is the critical output that flows into both remaining calls. This is why creating the space must be first - it unlocks everything else.


Memory Tip

Think of it like hosting a meeting room:

Build the room → Invite the guest → Speak

You can't invite someone to a room that doesn't exist, and there's no point speaking before your guest arrives. The API enforces the same real-world logic through its ID dependency chain.

Topics

#Webex Teams API#REST API#Space management#Python requests

Community Discussion

No community discussion yet for this question.

Full 300-835 Practice