How to create a webhook listener using Python
Use Case Scenario:
Create a Python Webhook listener using your local machine and send a test data to confirm that the webhook was able to received it.
In your Python IDE, install Flask
pip install Flask
Create a webhook listener. Copy the code to your Python IDE
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/webhook', methods=['POST'])
def webhook():
capturedata = request.json
firstname = format(capturedata['body']['profile']['firstname']
print(firstname)
return capturedata
app.run(host='192.168.1.7', port=8000)
Create a sample application to send a json data. Copy and paste the code in your Python IDE
import requests
from requests import request
import json
webhook_url = "http://192.168.1.7:8000/webhook"
testdata = {
"body": {
"profile": {
"id": "123123-12312",
"firstname": "Code",
"lastname": "Gray",
"company": "We Help Code",
},
}
}
testresponse = request('POST', webhook_url, json=testdata)
print(testresponse.text)
Related Video:
Watch the explainer video to understand what is a webhook