# n8n

:::tip Available
This integration is active and ready to use on all Pro plans.
:::

Connect Frihet to n8n to automate workflows: automatic reminders, CRM synchronization, custom notifications, and more.

## What is it for?

With n8n integrated:

- **Automatic Reminders** — Sends emails when an invoice is due
- **CRM Synchronization** — New clients are created in Salesforce, Pipedrive, etc.
- **Custom Notifications** — Slack, email, Telegram, custom webhook
- **Complex Workflows** — Conditionals, loops, logical branching
- **Webhook endpoints** — Other systems trigger actions in Frihet

## Requirements

- **n8n Account** — [Create one at n8n.io](https://n8n.io)
- **Basic n8n knowledge** — Or use pre-configured templates
- **Frihet API endpoint** — Consult the [REST API documentation](/desarrolladores/api-rest)
- **Frihet Pro or higher**

## Get Frihet credentials

### In Frihet

1. Go to **Settings** → **Integrations** → **n8n**
2. Click on **"Generate API Key"**
3. Copy the key (something like: `fh_live_XXXXXXXXXXXXXXXXX`)
4. Click on **"Create Webhook"**
5. Copy the webhook URL (to receive events)

Store both in a safe place.

## Connect Frihet to n8n

### Step 1: Create workflow in n8n

1. Go to [n8n.io](https://n8n.io)
2. **New workflow**
3. Add node: **Frihet** (search for it)

### Step 2: Configure credentials

1. In the Frihet node, go to **Credentials**
2. Click on **"Create new credential"**
3. Paste the Frihet **API Key**
4. Save

### Step 3: Choose action

In the node, choose what to do:

- Create invoice
- Create expense
- Create client
- Get client list
- Get invoice list
- Mark invoice as paid

## Common use cases

### Due date reminder

**When:** Every morning at 9am
**What it does:** Searches for overdue invoices and sends email to the client

```
n8n workflow:
1. Trigger: Every day at 09:00
2. Frihet Node: Get overdue invoices
3. Loop: For each invoice
4. Email Node: Send reminder email
5. Update in Frihet: Mark "Reminder sent"
```

### New client → CRM

**When:** Client is created in Frihet
**What it does:** Automatically adds it to Salesforce/Pipedrive

```
n8n workflow:
1. Trigger: Frihet Webhook (new client)
2. Frihet Node: Get client data
3. Salesforce Node: Create contact
4. Email Node: Notify the team
```

### Invoice paid → Slack Notification

**When:** An invoice is marked as paid
**What it does:** Sends notification to Slack with details

```
n8n workflow:
1. Trigger: Frihet Webhook (invoice paid)
2. Frihet Node: Get invoice details
3. Slack Node: Send formatted message
4. Sheet Node: Register in Google Sheets (optional)
```

### Create invoice from form

**When:** Someone completes a form
**What it does:** Automatically creates invoice in Frihet

```
n8n workflow:
1. Trigger: Form Webhook (TypeForm, Typebot, etc.)
2. Node: Process form data
3. Frihet Node: Create invoice
4. Email Node: Confirm to the client
```

## Pre-configured templates

n8n and Frihet offer ready-made templates:

1. In n8n, go to **Community** → **Templates**
2. Search for **"Frihet"**
3. Choose a template
4. Click on **"Use this template"**
5. Just configure credentials

### Available templates

- "Overdue invoice reminder"
- "Sync clients to Airtable"
- "Payment notifications in Slack"
- "Create invoices from Typeform"
- "Daily backup to Google Drive"

Use them as a base and customize.

## Frihet Webhook

Frihet automatically sends events to n8n. Consult the [full webhooks documentation](/desarrolladores/webhooks) for details on HMAC-SHA256 signature, retries, and all event types.

### Events that trigger webhook

| Event             | Data sent                               |
|-------------------|-----------------------------------------|
| **Invoice created** | ID, client, amount, due date            |
| **Invoice paid**    | ID, client, amount, payment date        |
| **Overdue invoice** | ID, client, amount, days overdue        |
| **Client created**  | ID, name, email, phone                  |
| **Expense created** | ID, category, amount, date              |
| **Payment received**| Invoice ID, client, amount              |

### Configure webhook in Frihet

1. **Settings** → **Integrations** → **n8n**
2. Click on **"Create Webhook"**
3. Choose which events to trigger (recommended: all)
4. Copy the webhook URL
5. In n8n, configure a **"Webhook"** node as a trigger with that URL

## Available actions in Frihet

### Create invoice

```javascript
Input:
- Client ID (or create new)
- Concept
- Amount
- Due date
- VAT

Output:
- Created invoice ID
- Document number
- Status
```

### Create expense

```javascript
Input:
- Category
- Amount
- Date
- Vendor (optional)

Output:
- Expense ID
- Confirmation
```

### Get list

```javascript
Input:
- Filter (date, client, status)
- Result limit

Output:
- Array of invoices/expenses/clients
```

### Mark as paid

```javascript
Input:
- Invoice ID
- Amount (optional)
- Payment method (optional)

Output:
- Confirmation
- Update date
```

## Full example: Daily reminder

### Objective

Every morning at 8am, if there are overdue invoices, send an email to the client.

### Workflow in n8n

**Step 1: Trigger**
```
Scheduler: Every day at 08:00
Timezone: Europe/Madrid
```

**Step 2: Get overdue invoices**
```
Node: Frihet
Action: Get Invoices
Filter: State = "unpaid" AND Due Date < Today
```

**Step 3: Loop over each invoice**
```
Loop Node: For each invoice in the result
  - Get client email
  - Calculate days overdue
```

**Step 4: Send email**
```
Node: Gmail / SendGrid
To: client email
Subject: "Invoice #{{$node.Frihet.data.number}} to collect"
Body:
  "Your invoice {{id}} for {{amount}} euros
   is overdue by {{days_overdue}} days.
   Please make the payment as soon as possible.
   [Payment link]"
```

**Step 5: Update in Frihet**
```
Node: Frihet
Action: Update Invoice
Update: reminder_sent = true
Update: reminder_date = today
```

## Bidirectional synchronization with CRM

### Create client in Frihet → Salesforce

```
1. Trigger: Frihet Webhook (client created)
2. Frihet: Get client data
3. Salesforce: Create Account
4. Salesforce: Create Contact
5. Frihet: Save Salesforce ID in client
```

### Create deal in Salesforce → Invoice in Frihet

```
1. Trigger: Salesforce Webhook (deal won)
2. Salesforce: Get deal data
3. Frihet: Create client (if new)
4. Frihet: Create invoice with deal amount
5. Salesforce: Update deal with link to Frihet
```

## Custom notifications

### Option 1: Email

```
Node: Gmail / SendGrid
Custom template with:
  - Your company logo
  - Invoice details
  - Payment link
```

### Option 2: Slack

```
Node: Slack
Message:
  ":moneybag: Invoice paid
   Client: {{client}}
   Amount: €{{amount}}
   Status: Paid ✅"
```

### Option 3: WhatsApp/Telegram

```
Node: Telegram / WhatsApp (via Twilio)
Message:
  "Hello {{name}},
   Your invoice #{{id}} is due in 3 days.
   [Pay here]"
```

### Option 4: Custom webhook

If you have your own system:

```
Node: HTTP POST
URL: https://your-system.com/frihet-webhook
Body:
  {
    "event": "invoice_paid",
    "invoice_id": "...",
    "amount": 1200,
    "client": "..."
  }
```

Your system processes as needed.

## Conditions and logic

You can add conditions:

```
IF invoice overdue MORE THAN 7 DAYS
  THEN send email + create task
ELSE IF overdue LESS THAN 7 DAYS
  THEN only send email
ELSE
  THEN do nothing
```

Or more complex branching:

```
IF client is "Premium"
  THEN call by phone
ELSE IF client is "Regular"
  THEN send email
ELSE
  THEN ignore
```

## Testing and debugging

### Execute workflow manually

1. In n8n, click on **"Execute"**
2. You see results step by step
3. If there is an error, it shows it with details
4. Adjust and re-execute

### Logs and history

1. Go to **Executions** in your workflow
2. You see each execution:
   - When it was executed
   - If it was successful
   - Execution time
   - Results of each node

### Test with test data

Before activating (scheduling), test:

1. Edit the trigger to **Manual**
2. Click on **"Execute"** several times
3. Verify that each node works
4. Then change to **Automatic Trigger** (scheduler)

## Limits and costs

### In n8n

- **Automatic Workflows:** Depends on your plan
- **Executions:** Free up to a certain limit
- **Nodes:** Unlimited
- **Integrations:** Hundreds available

### In Frihet

- **API calls:** Included in Pro (no additional limit)
- **Webhooks:** Unlimited
- **Data:** No special limit for n8n

## Troubleshooting

### "Webhook not triggering"

- Verify that the webhook is **active** in Frihet
- The event must match the configuration
- Check n8n logs: **Executions** → history
- If there's an HTTP error, check webhook status

### "Error: No credentials found"

- In n8n, verify that credentials are saved
- Copy the Frihet API Key again
- Recreate the credential

### "How to debug if something is not working?"

1. Add a **"Log"** node between steps to see intermediate data
2. Execute manually step by step
3. Go to **Executions** → full history
4. Search for the error in the logs

### "Can I use multiple workflows?"

Yes. You can have:

- Workflow 1: Daily reminders
- Workflow 2: CRM synchronization
- Workflow 3: Automatic backups
- All running in parallel

## Next steps

- Explore [n8n templates](https://n8n.io/workflows)
- Read the [REST API documentation](/desarrolladores/api-rest) and [webhooks](/desarrolladores/webhooks)
- Create your first custom automation

---

**Previous:** [Revolut Business](./revolut)
