# Webhooks

The **Webhooks** action in Qubitro Functions enables you to send data to external platforms and services automatically via HTTP requests. It's ideal for integrating Qubitro with other systems, triggering automated workflows, or forwarding real-time data.

### Key Features

* Supports HTTP methods: **POST**, **PUT**, **GET**, **DELETE**.
* Sends JSON payloads with dynamic device data.
* Customizable request headers.

### Examples

* Send device data to external analytics platforms.
* Trigger workflows on platforms like Zapier, Slack, or Microsoft Teams.
* Integrate Qubitro data with your custom APIs.

### Configuration

When triggered by defined conditions, Qubitro automatically sends an HTTP request with incoming data to the specified external webhook URL. You define the request method, headers, and JSON body content.

{% stepper %}
{% step %}
**Configure Basic Settings**

* **Set Debounce Period** *(optional)*: Specify a timeframe to avoid repeated triggers.
* **Enter Name**: Provide a descriptive, unique name for your function.
* **Provide Description**: Briefly describe the function's purpose.
  {% endstep %}

{% step %}
**Configure Webhook Template**

* **Webhook URL**: Enter the URL for your external service endpoint.
* **Request Method**: Select from POST, PUT, GET, or DELETE.
* **Request Headers** *(optional)*: Specify headers required by the external platform, such as authorization or content type.
* **Request Body Payload**: Define a JSON object to send data dynamically to your external service.

```json
{
  "maintenance_needed": "${{maintenance_needed}}",
  "timestamp": "${{timestamp}}",
  "acoustic_level": "${{acoustic_level}}",
  "anomaly_detected": "${{anomaly_detected}}",
  "equipment_health": "${{equipment_health}}",
  "pressure": "${{pressure}}",
  "temperature": "${{temperature}}",
  "flow_rate": "${{flow_rate}}",
  "humidity": "${{humidity}}",
  "random_key": "random_value"
}
```

Adjust the JSON body according to your requirements using placeholders
{% endstep %}

{% step %}
**Define Trigger Conditions**

* Choose a condition type (e.g., JavaScript Logic Builder) to determine when the webhook triggers.

```javascript
function run(){
  let temperature = "${{temperature}}";

  if (temperature > 30){
    trigger();
  }
};
```

In this example, a webhook request triggers when the temperature exceeds 30.
{% endstep %}
{% endstepper %}

### Common Errors & Troubleshooting

<details>

<summary>Webhook not triggering</summary>

* Verify the webhook URL is correct and accessible.
* Ensure your JavaScript logic conditions are met and error-free.
* Confirm your external service endpoint can accept your chosen HTTP request method.

</details>

<details>

<summary>Incorrect or missing data in payload</summary>

* Ensure JSON placeholders match exactly the keys in your device data payload.
* Confirm the selected request method and headers match the external system's requirements.

</details>

<details>

<summary>Receiving unexpected response or errors</summary>

* Check the external service logs for detailed error messages.
* Validate the JSON structure and ensure data types are correct.
* Test webhook manually using tools like Postman.

</details>


---

# 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://docs.qubitro.com/platform/functions/rule-function/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.
