Clearmargin
Integrations

n8n Integration

Step-by-step guide to connecting Clearmargin with n8n using webhooks and the HTTP Request node.

Build powerful automation workflows with n8n using Clearmargin webhooks and HTTP Request nodes. Works with both self-hosted n8n and n8n Cloud.

What you need

  • A Clearmargin account (admin or owner role)
  • An n8n instance (self-hosted or n8n Cloud)
  • A Clearmargin API key (for actions) — create one at Settings > API Keys
  • About 10 minutes

Part 1: Set Up Triggers (Clearmargin to n8n)

Use Clearmargin webhooks to trigger n8n workflows when events happen in your account.

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). The production URL is what Clearmargin will send events to when your workflow is active.

Configure the webhook in Clearmargin

Go to Settings > Webhooks in your Clearmargin dashboard. Click Add Webhook and paste the n8n production URL. Select the events you want to receive — for example, invoice_paid, payout_paid, proposal_accepted, client_created, or time_entry_created. Optionally set a signing secret to enable HMAC signature verification (recommended for production).

Activate and test

Activate the n8n workflow, then trigger an event in Clearmargin (e.g., create a test client). The Webhook node should receive the event payload with the full resource data. You can then add downstream nodes — IF conditions, data transformations, Slack messages, HTTP requests to other APIs, and more.

Part 2: Set Up Actions (n8n to Clearmargin)

Use n8n HTTP Request nodes to read and write data in Clearmargin.

Create an API key

Go to Settings > API Keys in Clearmargin and create a new key. Select the permission scopes you need (e.g., clients:read, clients:create, invoices:read). Copy the key — it is only shown once.

Add an HTTP Request node

In n8n, add an HTTP Request node to your workflow. Configure it to call the Clearmargin API:

Method: GET (or POST/PATCH/DELETE)
URL: https://www.clearmargin.app/api/clients

Authentication: Header Auth
  Header Name: Authorization
  Header Value: Bearer sk_live_your_key_here

Headers:
  Content-Type: application/json

For POST and PATCH requests, add a JSON body with the fields you want to create or update.

Use credentials for security

Instead of hardcoding the API key in each node, create an n8n credential of type Header Auth with your Clearmargin API key. Name it "Clearmargin API" and set the header name to Authorization with value Bearer sk_live_your_key_here. This keeps the key secure, encrypted, and reusable across multiple HTTP Request nodes in any workflow.

Webhook Signature Verification

If you set a signing secret on your Clearmargin webhook, you can verify the HMAC-SHA256 signature in n8n using a Code node placed after the Webhook 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;

The signature is computed over the concatenation of the timestamp, a period, and the raw JSON body. This prevents replay attacks because the timestamp is included in the signed payload.

Example Workflows

Daily invoice summary Cron trigger (daily at 9am) → HTTP Request (GET /api/invoices?where[status][equals]=sent) → Aggregate total outstanding → Send Slack message with the count and total amount of unpaid invoices.

New client onboarding Form submission (Typeform, Google Forms, etc.) → HTTP Request (POST /api/clients with name and email from form) → Send welcome email via SendGrid → Create Trello card for onboarding tasks.

Payment to accounting Webhook (invoice_paid event) → Code node (transform payload to accounting format) → HTTP Request (POST to your accounting API) → Log result to Google Sheets for audit trail.

Reference

  • API Reference — Full endpoint documentation, query syntax, and examples
  • Webhook Events — All available webhook event types and payload formats
  • API Keys — Create and manage your API keys

On this page