# Using Webhooks

## Common Use Cases

**Billing Notifications:** Automatically notify your accounting system when a payment is processed. This can help streamline financial operations and ensure your records are always up-to-date.

**Customer Management:** Update your CRM system with new customer information whenever a subscription is created or modified. This keeps your customer data consistent and current across all platforms.

**Inventory Management:** Synchronize your inventory system with customer orders. When a new order is placed, the webhook can trigger updates to your inventory, helping you manage stock levels more efficiently.

**Analytics and Reporting:** Send event data to your analytics platform to track important metrics such as subscription renewals, cancellations, and other key performance indicators. This enables more accurate reporting and deeper insights into your business’s performance.

## Preparing Your Software for Webhook Integration

Before implementing Fungies webhooks, you must prepare your software environment. This involves setting up an endpoint to receive the webhook data, ensuring your system can process the data, and configuring security measures to protect your webhook endpoint.

### Step 1: Setting Up an Endpoint

#### What Is an Endpoint?

An endpoint is a URL on your server that listens for incoming webhook data. When an event occurs in Fungies that triggers a webhook, the data is sent to this endpoint.

#### How to Set Up an Endpoint

1. Choose a URL: Decide on a URL for your webhook endpoint. This could be something like `https://yourdomain.com/webhooks/fungies`.
2. Create a Route: In your software, create a route that corresponds to the endpoint URL. This route will handle incoming POST requests from Fungies.

Parse Incoming Data: Ensure your endpoint can parse the incoming JSON data. Most modern web frameworks, like Express for Node.js, Flask for Python, or Laravel for PHP, have built-in methods for handling JSON data.

#### Testing Example for Setting Up an Endpoint

1. Login the <https://webhook.site/> and it will be assigned a webhook handler that can accept webhook requests with POST/GET methods.
2. Copy and store the “**Your unique URL**”.

<figure><img src="/files/8zRFq3L0jvaZWyrfO7D4" alt=""><figcaption><p>Testing Example Image for Setting Up an Endpoint</p></figcaption></figure>

## Configuring Webhooks in Fungies

Now that your software is ready to receive webhooks, the next step is to configure the webhook settings in Fungies.

**Step 1:** Go to the Fungies platform at [https://app.Fungies/login](https://app.fungies.io/login). Log in using your credentials and click on the '**Sign in** **with Email**' button.

<figure><img src="/files/B9WxwKxS3sIjDbf8T1RB" alt=""><figcaption><p>Sign in into Fungies.io account Image</p></figcaption></figure>

**Step 2:** Navigate to the Developers section, where you'll find the following options:

1. Webhooks
2. API Keys

<figure><img src="/files/Pf1aojvtQKuEuR5Pnwbx" alt=""><figcaption><p>Navigate to Fungies.io Developers Section Image</p></figcaption></figure>

### Generating the API Keys

An API key (secret key) will be used to sign webhook events. While you can use any string for the key, it should be kept secret and used to verify the event signatures.

**Step 1:** To generate the API key, click on the '**API Keys'** option and then select the '**Generate API Key**' button.

<figure><img src="/files/RGy150igwRYknTGexVqq" alt=""><figcaption><p>Navigate to Generating the API Keys Image</p></figcaption></figure>

**Step 2:** After clicking the '**Generate API Key**' button, the Fungies system will instantly create a secret key. Click the '**Copy**' button to save the secret key to your clipboard.

<figure><img src="/files/MnyTcS70qMBBvpZxjdYy" alt=""><figcaption><p>Copy the Generated API Key Image</p></figcaption></figure>

### Creating a New Webhook

**Step 1:** Click on the '**Webhooks**' option to access the webhook configuration page, then select the '**Create a webhook**' button.

<figure><img src="/files/QczciB0ElLik7Cs8BLGN" alt=""><figcaption><p>Creating a New Webhook Image</p></figcaption></figure>

**Step 2:** Paste the URL you copied from '**Your unique URL**' into the '**Testing Example for Setting Up an Endpoint**.'

**Note:** This URL is for testing purposes only. You can use your custom application domain URL instead.

<figure><img src="/files/jtFlygGunHSaCaVU7A6a" alt=""><figcaption><p>Create a Webhook URL Image</p></figcaption></figure>

**Step 3:** Copy the secret key from the '**API Keys**' page and paste it into the designated field.

<figure><img src="/files/1VfapYSmxkquHKbhJce6" alt=""><figcaption><p>Creating a Secret Key Image</p></figcaption></figure>

**Step 4:** Select the webhook event you'd like to trigger. The chosen event will be triggered, providing real-time updates to your software application.&#x20;

> These instructions are based on the "**On Payment Succesfull**" event type. To configure the other event types you can go through the "[**Types of Webhooks**](https://help.fungies.io/~/changes/WXReAtv0bIUUrsPqOpqn/for-saas-developers/types-of-webhooks?r=SxyOz9upk7sUeMmrk1ZS)" page.

<figure><img src="/files/jUElFLfouI9EO87atnZH" alt=""><figcaption><p>Selecting the Webhook Events Image</p></figcaption></figure>

**Step 5:** Click on the “**+ Create Webhook**” button to set up the webhook.

<figure><img src="/files/XjJbaqNg2tUaVQ25Mv23" alt=""><figcaption><p>Click the Create Webhook Button Image</p></figcaption></figure>

You can view the successfully created webhooks on the Webhooks page.

<figure><img src="/files/Y14qMiDuDnUmz2og1JT4" alt=""><figcaption><p>Successfully Created Webhooks List on the Webhooks page Image</p></figcaption></figure>

### Testing the Webhook

Before going live, use the “**Test Webhook**” feature in Fungies to send a sample payload to your endpoint.

**Step 1:** Click on the webhook which you want to test.

<figure><img src="/files/cUZTw5Dezln7ltukeiKw" alt=""><figcaption><p>Clicking on the Created Webhook for Test Image</p></figcaption></figure>

**Step 2:** A webhook configuration page will open. Click the '**Test**' button to begin the webhook testing.

<figure><img src="/files/lsqMKAw67D9xBZ2i4KNu" alt=""><figcaption><p>Clicking on the Test Button for Webhook Test Image</p></figcaption></figure>

**Step 3:** Clicking the '**Test**' button will open a window where you can choose the details for the webhook event you want to trigger for the test.

* Select the webhook event type.
* Choose the item name, if applicable.
* Select the customer name, if applicable.

<figure><img src="/files/o5xMJR4psYqQgEcyWxNG" alt=""><figcaption><p>Enter the Webhook Details for Test Image</p></figcaption></figure>

**Step 4:** Click the '**Send**' button to trigger the webhook.

<figure><img src="/files/TrrgLKPPzx0Zq7hNNWM7" alt=""><figcaption><p>Clicking on the Send Button Image</p></figcaption></figure>

You can now view the trigger details (payload) on the endpoint handler you configured during the 'Setting Up an Endpoint' section.

<figure><img src="/files/8WjerwMAlOXcUKibEJSi" alt=""><figcaption><p>View the Triggered Details (payload) on the Endpoint Handler Image</p></figcaption></figure>

#### Example of Request Payload Object (payment\_success)

This is a request body payload object for the payment\_success event

```
{
  "id": "f4cbd202-89c5-4538-b44b-11b2b7fa36ea",
  "type": "payment_success",
  "testMode": true,
  "data": {
    "items": [],
    "order": {
      "id": "47f68b70-898e-4dc8-99bd-9f30ce73c2f4",
      "totalItems": 0,
      "orderNumber": "2OJ3DJ0VP0CN"
    },
    "customer": {
      "id": "6e53e763-842e-4b19-872a-f02dfc8dc109",
      "email": "test@Fungies"
    }
  },
  "idempotencyKey": "f4cbd202-89c5-4538-b44b-11b2b7fa36ea"
}
```

#### Example of Response Object: 200

This is a response object for the payment\_success event

```
{
"data":"This URL has no default content configured. <a href="https://webhook.site/#!/view/7b736426-27aa-4b85-bda3-5d84fbc401eb">View in Webhook.site</a>."
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.fungies.io/for-saas-developers/using-webhooks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
