> ## Documentation Index
> Fetch the complete documentation index at: https://doc.withedge.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhook

> Webhooks are a powerful feature that allows your application to receive real-time notifications about specific events that occur within the Edge platform. By setting up webhooks, you can automate processes, update records, and trigger workflows in your application as soon as an event happens.

## What Are Webhooks?

Webhooks are user-defined HTTP callbacks that are triggered by specific events. When one of those events is triggered, Edge will send an HTTP POST request to the webhook URL you specify. This request contains details about the event, allowing your application to handle the event data in real-time.

<Info>
  Webhooks enable your application to respond to events as they happen, ensuring that your system stays up-to-date without the need for constant polling.
</Info>

### Common Use Cases for Webhooks

<CardGroup cols={2}>
  <Card title="Payment Notifications">
    Get notified when a payment is successful or fails, and update your records accordingly.
  </Card>

  <Card title="Account Updates">
    Receive updates when an account is created, updated, or deleted.
  </Card>

  <Card title="Transaction Events">
    Monitor transactions in real-time, enabling immediate action or analysis.
  </Card>

  <Card title="Other Custom Events">
    Set up webhooks for any custom events that are crucial to your business operations.
  </Card>
</CardGroup>

## Setting Up Webhooks on Edge Dashboard

To start using webhooks, you need to configure them through the Edge Dashboard. Follow the steps below to set up your webhooks:

<Steps>
  <Step title="Log in to the Edge Dashboard">
    Begin by logging in to your Edge account. Once logged in, navigate to the Dashboard.
  </Step>

  <Step title="Navigate to the Webhooks Section">
    In the Dashboard, find the **Webhooks** section. This is typically located under the **API Settings** or **Integrations** tab.
  </Step>

  <Step title="Create a New Webhook">
    <ul>
      <li><strong>Click on "Create Webhook":</strong> This will open a form where you can specify the details of your webhook.</li>
      <li><strong>Enter the Webhook URL:</strong> Provide the URL where you want to receive webhook notifications. Ensure that this URL is accessible from the public internet.</li>
      <li><strong>Select Events to Monitor:</strong> Choose the specific events you want to receive notifications for. You can select multiple events based on your application's needs.</li>
      <li><strong>Set Secret Key (Optional):</strong> For added security, you can set a secret key that Edge will include in the header of each webhook request. This allows you to verify that the requests are genuinely coming from Edge.</li>
      <li><strong>Save the Webhook:</strong> Once you've filled in the details, save the webhook configuration.</li>
    </ul>
  </Step>

  <Step title="Test the Webhook">
    After setting up the webhook, you should test it to ensure it works as expected.

    <ul>
      <li><strong>Send Test Event:</strong> Use the Edge Dashboard to send a test event to your webhook URL. This allows you to verify that your server correctly receives and processes the webhook data.</li>
      <li><strong>Verify Response:</strong> Check that your application responds with a `200 OK` status code. This indicates that the webhook was received and processed successfully.</li>
    </ul>
  </Step>
</Steps>

<Tip>
  Ensure that your server responds quickly to webhook requests. Webhooks that do not receive a `200 OK` response may be retried multiple times by Edge.
</Tip>

Here’s the guide rewritten using the **Steps** component to clearly outline the process for handling webhooks in your application:

## Handling Webhooks in Your Application

When your application receives a webhook, it’s important to handle it efficiently and securely. Follow these steps to manage incoming webhooks:

<Steps>
  <Step title="Step 1: Parse the Incoming Request">
    Webhooks are sent as HTTP POST requests with a JSON payload. Your application needs to parse this payload to extract the event data.

    ```json
        {
            "event": "payment.success",
            "data": 
            {
            "transactionId": "12345",
                "amount": 10000,
                "currency": "NGN",
                "status": "successful"
            }
        }
    ```
  </Step>

  <Step title="Step 2: Verify the Webhook">
    If you have set a secret key, you should verify the signature included in the webhook request headers. This verification ensures that the request is authentic and actually from Edge.

    ```http
        POST /webhook-endpoint HTTP/1.1
        Host: yourapplication.com
        Content-Type: application/json
        X-Edge-Signature: sha256=abcdef1234567890
    ```
  </Step>

  <Step title="Step 3: Handle the Event">
    Based on the event type and data, your application should execute the appropriate logic. For example, if you receive a `payment.success` event, you might update the transaction status in your database.
  </Step>

  <Step title="Step 4: Respond to the Webhook">
    Always respond to the webhook request with a `200 OK` status code once your application has processed the event. This response tells Edge that the webhook was received and handled successfully.

    ```http
        HTTP/1.1 200 OK
        Content-Type: application/json

        {
            "status": "success"
        }
    ```
  </Step>
</Steps>

<Warning>
  Ensure your webhook endpoint is secure. Consider implementing rate limiting and verifying the signature of incoming requests to prevent unauthorized access.
</Warning>
