Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to send a test webhook POST request using curl.
Rest API
curl [1] 'https://example.com/webhook' -d '{"event":"test"}'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST
Omitting the HTTP method option
✗ Incorrect
The -X POST option tells curl to send a POST request, which is required for webhook testing.
2fill in blank
mediumComplete the code to verify the webhook payload signature in Python.
Rest API
import hmac import hashlib def verify_signature(payload, signature, secret): expected = hmac.new(secret.encode(), payload, hashlib.sha256).hexdigest() return hmac.compare_digest(expected, [1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with payload instead of signature
Not encoding the secret
✗ Incorrect
The function compares the expected signature with the received signature to verify authenticity.
3fill in blank
hardFix the error in the Node.js webhook test server code to parse JSON body correctly.
Rest API
const express = require('express'); const app = express(); app.use([1]); app.post('/webhook', (req, res) => { console.log(req.body); res.sendStatus(200); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using express.urlencoded() for JSON
Not using any body parser middleware
✗ Incorrect
express.json() middleware parses incoming JSON payloads so req.body is populated.
4fill in blank
hardFill both blanks to create a Python dictionary comprehension that filters webhook events with type 'payment'.
Rest API
filtered_events = {event['id']: event for event in events if event[1] [2] 'payment'} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '=='
Accessing wrong dictionary key
✗ Incorrect
We access the 'type' key and check if it equals 'payment' to filter events.
5fill in blank
hardFill all three blanks to build a JavaScript object from webhook data filtering only events with status 'success'.
Rest API
const successEvents = Object.fromEntries( Object.entries(data).filter(([[1], [2]]) => [3] === 'success') );
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'status' instead of 'value.status'
Swapping key and value names
✗ Incorrect
We destructure entries into key and value, then filter by value.status equal to 'success'.