0
0
Rest APIprogramming~20 mins

Webhook payload design in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Webhook Payload Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this webhook payload validation code?

Consider a webhook payload validation function that checks if the payload contains the required fields event and timestamp. What will be the output of the following code when given the payload {"event": "user_signup", "timestamp": 1680000000}?

Rest API
def validate_payload(payload):
    required_fields = ['event', 'timestamp']
    for field in required_fields:
        if field not in payload:
            return f"Missing field: {field}"
    return "Payload valid"

payload = {"event": "user_signup", "timestamp": 1680000000}
print(validate_payload(payload))
APayload valid
BMissing field: timestamp
CMissing field: event
DKeyError
Attempts:
2 left
💡 Hint

Check if all required keys exist in the payload dictionary.

🧠 Conceptual
intermediate
1:30remaining
Which option best describes the purpose of including a signature in a webhook payload?

Why do webhook payloads often include a signature or hash value?

ATo encrypt the payload data for privacy
BTo compress the payload for faster transmission
CTo verify the payload integrity and authenticity
DTo format the payload as JSON
Attempts:
2 left
💡 Hint

Think about how the receiver can trust the source of the webhook.

🔧 Debug
advanced
2:00remaining
What error does this webhook payload parsing code raise?

Given the following Python code that parses a webhook payload, what error will it raise?

Rest API
import json

def parse_payload(payload_str):
    data = json.loads(payload_str)
    return data['user']['id']

payload = '{"user": null}'
print(parse_payload(payload))
AKeyError
BTypeError
CValueError
DAttributeError
Attempts:
2 left
💡 Hint

Consider what happens when you try to access a key on a NoneType object.

📝 Syntax
advanced
1:30remaining
Which option produces the correct JSON payload with nested data?

Which of the following strings is a valid JSON payload representing a webhook event with nested user data?

A{"event": "order_created", "user": {"id": 123, "name": Alice}}
B{'event': 'order_created', 'user': {'id': 123, 'name': 'Alice'}}
C{"event": "order_created", "user": {id: 123, name: "Alice"}}
D{"event": "order_created", "user": {"id": 123, "name": "Alice"}}
Attempts:
2 left
💡 Hint

Remember JSON requires double quotes for keys and string values.

🚀 Application
expert
1:30remaining
What is the number of top-level keys in this webhook payload?

Given the following webhook payload, how many top-level keys does it contain?

Rest API
{
  "event": "payment_received",
  "timestamp": 1680001234,
  "data": {
    "payment_id": "abc123",
    "amount": 49.99,
    "currency": "USD"
  },
  "metadata": {
    "customer_id": "cust789",
    "notes": "First payment"
  }
}
A4
B3
C2
D5
Attempts:
2 left
💡 Hint

Count only the keys at the outermost level of the JSON object.