Test a Webhook Locally

To test a webhook locally, you need to use a network tunneling solution to redirect external traffic to a locally hosted endpoint. This article explains how to test your webhook handler using ngrok, a widely adopted networking tunneling tool. However, you can use any tunneling solution of your choice.

In the Wix Dev Center, each webhook includes a code sample to assist you in developing your webhook handler. These samples are configured to handle webhook events using an Express server. If you already have this sample, skip to test your handler. Otherwise, get a code sample.

Step 1 | Get a code sample

To get a code sample for an existing webhook:

  1. Go to your app in the Dev Center.

  2. From the side menu, click Webhooks.

  3. Next to the relevant webhook, click on the menu icon, and select View code sample.

Step 2 | Test your handler

To locally test your webhook handler without deploying your server:

  1. Install and configure ngrok on your local machine. For guidance, see the ngrok quickstart.

  2. Start your webhook handler. To start the handler from the code sample, run the following command:

    Copy
    1
    node server.js

    This action starts the webhook handler on the local port 3000.

  3. Start ngrok and expose the same port as your handler. For example:

    Copy
    1
    ngrok http http://localhost:3000

    If your handler isn't listening on port 3000, substitute 3000 with the relevant port number.

  4. Once ngrok is running, copy the Forwarding URL provided in the terminal output.

  5. In the Dev Center, go to your webhook. In the Callback URL field, paste the ngrok Forwarding URL followed by the endpoint of your handler. In the provided code sample, the endpoint is /webhook.

    Note: Restarting ngrok generates a new Forwarding URL. In such instances, ensure to update the Callback URL accordingly.

  6. Click Trigger a test.

If using the code sample provided with the webhook, the handler should output the payload of the received webhook call.

Was this helpful?
Yes
No