# n8n

This guide demonstrates how to integrate Scorable Judges into an n8n workflow to evaluate and refine AI-generated responses before delivering them to users.

## Architecture Overview

The flow is as follows: User → Website Chatbot → n8n Webhook → HTTP Request (Scorable Judge) → Refined AI Response → Website

## Prerequisites

* An n8n instance (Cloud or Self-hosted)
* A Scorable account
* A website where the chatbot will be embedded

***

## Step 1: Create a Webhook Node in n8n

1. Open a new workflow canvas in n8n.
2. Add a **Webhook** node.

**Webhook Settings:**

* **HTTP Method**: `POST`
* **Webhook URL Type**: `Product URL`
* **Path**: Copy and paste the last segment of the Product URL

**CORS Configuration:**

* Enable **Allowed Origins (CORS)**
* Add your website domain (e.g., `https://yourwebsite.com`)

***

## Step 2: Create a Judge on Scorable

Create a **Judge** on Scorable and define the chatbot's scope, tone of voice, and evaluation rules.

![scorableai](https://github.com/user-attachments/assets/35301c66-03b2-453b-97e7-5e8db8aedd35)

After creation, copy the following values:

* **Judge ID**
* **API Key**

![kod](https://github.com/user-attachments/assets/fffb1fa9-1e0c-48cf-b6a8-358019af31a5)

***

## Step 3: Configure the HTTP Request Node

Add an **HTTP Request** node in n8n.

![req](https://github.com/user-attachments/assets/7f79a8e4-e19e-4321-8ca4-6aa06fec921d)

**Basic Configuration:**

* **Method**: `POST`
* **URL**:

  ```
  https://api.scorable.ai/v1/judges/JUDGE_ID/refine/openai/chat/completions
  ```

  *(Replace `JUDGE_ID` with your own judge ID)*

**Headers:**

Enable **Send Headers** and add:

| Name          | Value                  |
| ------------- | ---------------------- |
| Content-Type  | `application/json`     |
| authorization | `Api-Key YOUR_API_KEY` |

***

## Step 4: Configure the Request Body

Enable **Send Body** and configure the request as JSON.

```json
{
  "model": "gpt-5.2",
  "messages": [
    {
      "role": "system",
      "content": "WRITE YOUR OWN SYSTEM PROMPT HERE. Define who your chatbot is, how it should behave, and what kind of answers it should give."
    },
    {
      "role": "user",
      "content": "{{$json.body.message}}"
    }
  ]
}
```

***

## Step 5: Respond to the Webhook

Add a **Respond to Webhook** node.

**Response Body:**

```javascript
{{
  {
    "reply": $node["HTTP Request"].json["choices"][0]["message"]["content"]
  }.toJsonString()
}}
```

**Response Headers:**

| Name         | Value              |
| ------------ | ------------------ |
| Content-Type | `application/json` |

***

## Final Result

The n8n workflow will now handle user messages, send them to Scorable for evaluation and refinement, and return only the approved responses.

![flow end](https://github.com/user-attachments/assets/5987d460-f73b-4daf-a8d8-2479a13e63f9)
