In this tutorial, we will use localtunnel to test both the widget and the webhook endpoint on your local machine.
Downloading and Installing LocalTunnel
The keys we provide do not work on localhost. This is because they are your production keys and for security reasons, they should only work on your domain.
Similarly, while testing your webhook, your local host is unreachable from the internet. Hence even if you set your webhook to a localhost endpoint it will not get delivered to the app running on your local computer.
To solve both of these problems, you can install LocalTunnel. The official website for this tool can be found at LocalTunnel.me
You can install this tool by running the command
npm install -g localtunnel
Testing Your Widget Locally
Once the tool is installed you need to run it like this:-
After getting the app name from us, for testing the UI, you need to test it like this:-
lt --port port-to-ui-app --subdomain magiklabs-appname-ui
This will open an ssh tunnel from https://magiklabs-appname.loca.lt to your local host.
Now you can open this URL in your browser to test whether the widget is working correctly.
Testing your Webhook L
For testing the webhook, you can start a local tunnel like this:
lt --port port-to-ui-app --subdomain magiklabs-appname
Then you can use the Webhook Update Endpoint in the API Endpoints section to update your new endpoint to this value:
curl --location --request POST 'https://api.magiklabs.io/api/v1/business/webhook/' \
--header 'api-secret: your-api-secret' \
--header 'Content-Type: application/json' \
--data-raw '{
"url": "https://magiklabs-appname.loca.lt/path/to/webhook"
}'
After that, you can test out your endpoint by calling this endpoint. This endpoint sends a dummy request to your server (running on localhost or any real web server).
curl --location --request POST 'https://api.magiklabs.io/api/v1/business/webhook/test' \
--header 'api-secret: your-api-secret' \
--header 'Content-Type: application/json'
Do not forget to use replace your-api-secret
with the real secret provided by you.