Guide for using ngrok for webhook testing

Motivation

For testing webhooks or to share the site temporarily with others.

Steps

Step 1: Install ngrok

image

Note: :warning: Do not start the endpoint!

Step 2: Start your bench

bench start

Step 3: Run ngrok on a new bench terminal

ngrok http PORT_NUMBER --host-header=SITE_NAME

Result: The URL will change every time you run ngrok

image

https://69be-2402-3a80-1318-e921-3274-6abe-4b87-6dde.ngrok-free.app

Step 4: If you want to stop, just press: Ctrl + C

Step 5: If you want to use it as a webhook, then:

  • Example of a webhook listener:
@frappe.whitelist(allow_guest=True)
def webhook_listener():
    pass
  • Your webhook URL:
https://69be-2402-3a80-1318-e921-3274-6abe-4b87-6dde.ngrok-free.app/api/method/WEBHOOK_PYTHON_PATH

How to get webhook data

# to get perticular header
id = frappe.get_request_header("ID")

# to get request headers
request_headers = str(frappe.request.headers)

# to get payload
payload = json.loads(frappe.request.data)
2 Likes