Skip to main content

SaaS integrations

Extend your SaaS without complicating your core product

Build the integration, report or custom API a customer asked for, and deploy it with no infrastructure to set up. The first one you build becomes the template for the next customer.

No infrastructure to set up · Reusable across customers · Data stored in the EU

Why do customer requests end up in the core product?

A large customer signs, and the contract includes an integration with their ERP. Another wants a weekly export in a format only their finance team uses. A third needs an API endpoint shaped around their own data warehouse.

Each request is reasonable on its own. Built into the core product, though, every one of them adds a code path most customers never touch, a credential to store, and a deploy to coordinate with the rest of the platform.

Running them in your own cloud has a cost too. Someone has to provision the function, the queue and the scheduler for each one, and then keep them patched and monitored for as long as the contract runs.

A coding agent can now write most of this code in an afternoon. The hours go into finding somewhere to run it, and into looking after it for the length of the contract.

Inside your product, or beside it

Built into your core product or cloudCodehooks
Customer-specific code paths in the main codebaseYour product stays the same for every customer
A function, queue and scheduler to provision per requestNo infrastructure to set up: routes, queues, cron and a database come with every project
Each customer integration is built from scratchDeploy the same code to a new customer space and change the settings
Customer credentials stored next to your production secretsEncrypted environment variables per space
Changes wait for the core release cycleDeploy one integration in seconds, on its own schedule
Failures land in the same alerts as your productLogs, queue status and stored errors per integration

One customer's integration in one file

Your product sends an event. A worker pushes it into the customer's ERP, a weekly job retries failures and builds a report, and the customer's dashboard reads that report through its own API route.

index.js
import { app, Datastore } from 'codehooks-js';

// Your product posts events here with an API token
// (coho add-token), so the default auth check applies
app.post('/events', async (req, res) => {
const conn = await Datastore.open();
const event = await conn.insertOne('events', {
...req.body,
receivedAt: new Date().toISOString(),
pushed: false,
});
await conn.enqueue('push-to-erp', { id: event._id });
res.status(202).end();
});

// Maps your data model to this customer's ERP
app.worker('push-to-erp', async (req, res) => {
const conn = await Datastore.open();
const { id } = req.body.payload;
const event = await conn.findOneOrNull('events', id);

try {
const r = await fetch(`${process.env.ERP_URL}/invoices`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.ERP_TOKEN}`,
},
body: JSON.stringify(toErpInvoice(event)),
});
if (!r.ok) throw new Error(`ERP replied ${r.status}`);
await conn.updateOne('events', id, { $set: { pushed: true } });
} catch (err) {
// Stays unpushed, so the Monday job queues it again
await conn.updateOne('events', id, { $set: { lastError: String(err) } });
}
res.end();
});

// Mondays at 07:00: retry failures and build the weekly report
app.job('0 7 * * 1', async (req, res) => {
const conn = await Datastore.open();
await conn.enqueueFromQuery('events', { pushed: false }, 'push-to-erp');

const since = new Date(Date.now() - 7 * 864e5).toISOString();
const events = await conn
.getMany('events', { receivedAt: { $gt: since } })
.toArray();
await conn.insertOne('reports', {
week: since,
invoices: events.length,
total: events.reduce((sum, e) => sum + (e.amount || 0), 0),
});
res.end();
});

// The customer's dashboard reads this with a read-only token
app.get('/reports/latest', async (req, res) => {
const conn = await Datastore.open();
const [latest] = await conn
.getMany('reports', {}, { sort: { week: -1 }, limit: 1 })
.toArray();
res.json(latest || {});
});

export default app.init();

toErpInvoice() is your mapping for this customer. ERP_URL and ERP_TOKEN are set per space with coho set-env.

How does one integration become a template for the next?

Keep the integration in its own repository. When the next customer asks for the same thing, add a space for them, set their credentials and deploy the same code. The parts that change between customers (the address of their system, their token and how your fields map to theirs) live in environment variables and a mapping module, so everything else is shared and tested already.

terminal
# A second customer wants the same ERP integration
coho add globex

# Their endpoint and credentials, stored on their space only
coho set-env ERP_URL https://erp.globex.example --space globex
coho set-env ERP_TOKEN <their-token> --encrypted --space globex

# Same code, their own data, tokens and logs
coho deploy --space globex

There is nothing to provision for the new customer. The space comes with its own database, queues, cron and API tokens, and a fix to the shared code can be deployed to every customer space from the same repo.

Questions SaaS teams ask first

Including where this sits next to the cloud you already run

Does this replace our existing cloud setup?
No. Your product keeps running where it runs now, and nothing about it moves. Codehooks sits beside it and talks to it the way any external service would: your product sends events to a Codehooks endpoint (or Codehooks calls your public API on a schedule), and the integration code handles the customer's side from there.
How do we keep one customer separate from another?
You have two options. For strict isolation, give each customer its own space, which is a self-contained bundle of code, data, API tokens and environment variables. You create one with coho add and deploy to it with coho use and coho deploy. If you have many small customers on the same integration, one space with a customer ID on every record and per-customer settings in the database is simpler (extra spaces are an add-on beyond what your plan includes, so this also keeps the count down).
Where do the customer's credentials live?
In environment variables on the space, set with coho set-env and stored encrypted when you pass --encrypted. Your code reads them with process.env. They're kept apart from your own production secrets, which matters when a customer rotates a key or the contract ends and you need to remove everything that belongs to them.
Can the customer see the reports or call the API directly?
Yes. Routes need an API token or a valid JWT by default, so you can create a read-only token for a customer with coho add-token --readonly and give it to their dashboard or their data team. If your product already issues JWTs from a provider with a JWKS endpoint, coho jwks makes the same logins work against these routes. You can also serve a small dashboard from the same project, since frontend hosting is included.
What happens when the customer system is down?
The event is already stored in your database before the worker runs, so nothing is lost. In the example above, a failed push stays marked as unpushed with the error saved on the record, and the weekly job queues it again. Most real integrations run that retry pass nightly or hourly instead. If you'd rather have retries counted for you, the Workflow API has a maxRetries setting per step.
Where is the data stored?
In the EU, on servers in Amsterdam and Ireland.

Built with a coding agent

Let the agent deploy what it writes

A coding agent can write a customer integration from their API docs and a sample of your data in an afternoon. What usually slows it down is everything after that: where the code is deployed, where the customer's credentials go, and who notices when it breaks.

With Codehooks the agent can do the deploy too. It runs coho prompt for the API reference, writes the code, deploys to the customer's space with coho deploy, and reads coho log to check the first events. You review the change in a pull request like any other.

An agent can write the mapping between your data and theirs, but it can't tell you what the customer actually meant by a field. Getting that agreed is still a conversation with the customer.

Keep customer-specific work out of your core product

Each integration, report or custom API gets its own deploy, data and credentials, and your product stays the same for everyone.

A separate space per customer · Data stored in the EU