Tools
Webhook
Get Started

Get started

Step 1: Identify the Events to Monitor

The first step is to determine the events you want to receive notifications for. You can find a list of available events here.

Step 2: Set up a Webhook Endpoint

Create an HTTP endpoint to receive unauthenticated webhook requests using the POST method.

./pages/api/webhook.ts
import { NextApiRequest, NextApiResponse } from 'next'
 
export default async function webhook(
  req: NextApiRequest,
  res: NextApiResponse,
): Promise<void> {
  // ... get and process the event
  res.status(200).end()
}
 

Step 3: Handle Requests from Liteflow

To process events from Liteflow's webhooks, install the @nft/webhook library.

npm i @nft/webhook

The library will parse and verify the incoming requests to ensure they are coming from the Liteflow infrastructure. To secure the communication between your application and the Liteflow infrastructure, you will need your Liteflow secret.

./pages/api/webhook.ts
import { parseAndVerifyRequest } from '@nft/webhook'
import { NextApiRequest, NextApiResponse } from 'next'
 
export default async function webhook(
  req: NextApiRequest,
  res: NextApiResponse,
): Promise<void> {
  const { data, timestamp, type } = await parseAndVerifyRequest<SELECTED_EVENT>(
    req,
    process.env.LITEFLOW_WEBHOOK_SECRET,
  )
 
// ...do something with the event
 
res.status(200).end()
}
 
export const config = {
  api: {
    bodyParser: false,
  },
}

Built-in Retry Mechanisms

The Liteflow infrastructure will retry the webhook up to 5 times for any status code not 200.

Step 4: Register Your HTTPS URL

To connect your webhook to your Liteflow backend, go to your dashboard and add your newly created endpoint in the webhook section.

Local Development Considerations

Webhooks must be publicly accessible with an https url and cannot be hosted on localhost. To test webhooks locally, you can use tools such as ngrok (opens in a new tab) or localtunnel (opens in a new tab).