300-835 · Question #37
Refer to the exhibit. Drag and drop the code snippets from the bottom onto the blanks in the code to construct a Python script that creates a webhook to notify the administrator when a message is dele
The exhibit and code snippet options weren't included in your message - the options field shows {} (empty), so I can't tell you which specific blanks to fill or which options are correct for this particular drag-and-drop question. That said, I can give you a solid conceptual expl
Question
Explanation
The exhibit and code snippet options weren't included in your message - the options field shows {} (empty), so I can't tell you which specific blanks to fill or which options are correct for this particular drag-and-drop question.
That said, I can give you a solid conceptual explanation of this procedure so you understand the reasoning, which is often more useful for an exam than just the answer.
Overall Goal
A Webex webhook is an HTTP callback that Webex fires to a URL you control whenever a specified event occurs. The goal here is to register a webhook that listens for messages resource events with event type deleted, scoped to a room type of group, so an administrator gets notified when someone deletes a message.
The Correct Approach: Why a Webhook?
Webex uses a push model for events. Instead of your script constantly polling the API ("did anything happen yet?"), you register a webhook once and Webex calls your endpoint. This is the correct approach because:
- It's efficient - no polling overhead
- It's real-time - notification fires immediately on the event
- It's the only official mechanism for event-driven automation in Webex
Key Components of the Python Script
1. Authentication Header
headers = {
"Authorization": "Bearer <your_token>",
"Content-Type": "application/json"
}
Why necessary: Every Webex API call requires a Bearer token. Without it, you get a 401 Unauthorized. The Content-Type header tells Webex you're sending JSON in the body.
2. Webhook Payload (the body)
payload = {
"name": "Message Deleted Webhook",
"targetUrl": "https://your-server.com/webhook",
"resource": "messages",
"event": "deleted",
"filter": "roomType=group"
}
Why each field matters:
| Field | Purpose | Wrong if omitted |
|---|---|---|
name | Human-readable label | Still works, but unidentifiable in the dashboard |
targetUrl | Where Webex POSTs the event payload | Required - webhook creation fails |
resource | What object to watch (messages, memberships, etc.) | Required - no target to watch |
event | Which action triggers it (created, deleted, updated) | Required - fires on wrong events or fails |
filter | Narrows scope (e.g., roomType=group) | Without this, fires for direct messages too - not what's wanted |
3. POST to the Webhooks API
import requests
response = requests.post(
"https://webexapis.com/v1/webhooks",
headers=headers,
json=payload
)
Why POST: You are creating a new resource. Using GET would list existing webhooks, not create one.
Why json=payload: The requests library serializes the dict and sets the Content-Type automatically when you use json= (though explicitly setting it in headers is also fine/redundant here).
4. Verify the Response
print(response.status_code)
print(response.json())
Why necessary: A 200 or 200 Created confirms the webhook was registered. Printing the response body shows the webhook id, which you need if you later want to update or delete it.
What Goes Wrong If Steps Are Skipped or Reordered
- Skip auth header →
401 Unauthorized, script fails immediately - Wrong
resourceorevent→ webhook registers but never fires (or fires on wrong events) - Missing
filter→ admin gets notified for every deleted message including DMs, not just group rooms - Use GET instead of POST → returns a list of webhooks, creates nothing
- Skip response check → you won't know if the webhook was actually created or silently failed
Memory Tip
Think of it as CHEF:
Credentials → Hook payload → Endpoint (POST) → Feedback (check response)
The filter roomType=group is the detail most likely to trip you up - it's what makes this a group room webhook specifically, not a general message-deletion webhook.
If you can share the actual exhibit image or list the code snippet options, I can map them directly to the blanks and tell you exactly which goes where.
Topics
Community Discussion
No community discussion yet for this question.