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 Webhooks page of the app dashboard, 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. Select your app from the Custom Apps page in your Wix Studio workspace.

  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

    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

    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 Webhooks page of your app's dashboard, click on the menu icon next to the relevant webhook and select Edit callback URL.

  6. 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.

  7. Click Trigger a test.

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

Did this help?