Connect Clearmargin with n8n
Build powerful automation workflows with n8n using Clearmargin webhooks and HTTP Request nodes. Works with both self-hosted n8n and n8n Cloud.
What you will need
- A Clearmargin account (admin or owner role)
- An n8n instance (self-hosted or n8n Cloud)
- About 10 minutes
Part 1: Set up triggers (Clearmargin to n8n)
Add a Webhook node in n8n
Create a new workflow in n8n. Add a "Webhook" node as the trigger.
Set the HTTP method to POST. n8n will generate a unique webhook URL. Copy the "Production URL" (not the test URL).
Configure the webhook in Clearmargin
Go to Settings and add a new webhook with the n8n production URL.
Select the events you want to receive (e.g., invoice_paid, proposal_accepted).
Activate and test
Activate the n8n workflow, then trigger an event in Clearmargin. The webhook node should receive the event payload. You can then add downstream nodes to process the data.
Part 2: Set up actions (n8n to Clearmargin)
Create an API key
Go to Settings > API Keys and create a new key with the permissions you need.
Add an HTTP Request node
In n8n, add an "HTTP Request" node. Configure it to call the Clearmargin API:
Method: GET (or POST/PATCH/DELETE)
URL: https://app.clearmargin.app/api/clients
Authentication: Header Auth
Header Name: Authorization
Header Value: Bearer sk_live_your_key_here
Headers:
Content-Type: application/jsonUse credentials for security
Instead of hardcoding the API key, create an n8n credential of type "Header Auth" with your API key. This keeps the key secure and reusable across multiple nodes.
Webhook signature verification (optional)
If you set a signing secret on your Clearmargin webhook, you can verify the signature in n8n using a Code node:
const crypto = require('crypto');
const body = JSON.stringify($input.item.json.body);
const timestamp = $input.item.json.headers['x-webhook-timestamp'];
const signature = $input.item.json.headers['x-signature'];
const secret = 'your_webhook_secret';
const expected = crypto
.createHmac('sha256', secret)
.update(`${timestamp}.${body}`)
.digest('hex');
if (signature !== `sha256=${expected}`) {
throw new Error('Invalid webhook signature');
}
return $input.item;Example workflows
Daily invoice summary
Cron trigger (daily) → HTTP Request (GET /api/invoices?where[status]=sent) → Slack message with summary
New client onboarding
Form submission → HTTP Request (POST /api/clients) → Send welcome email → Create Trello card
Payment to accounting
Webhook (invoice_paid) → Transform data → POST to accounting API
Reference
- API Reference — Full endpoint documentation
- Webhook Events — All webhook event types
- API Keys — Create and manage API keys