---
title: Build your own integration
description: Connect your own system to Hydda One with a client id and secret, from creating the integration in the admin console to the first invoice on the queue.
---

This guide connects a system you build and run yourself, such as a sync to your own ERP. It uses invoicing as the example. Contract signing works the same way, and the differences are [at the end](#the-same-for-contract-signing).

You need no page of your own and no sign-in at a third party. An administrator sets the integration up in the admin console, and your system signs in with a client id and a client secret.

## What you will set up

```mermaid
sequenceDiagram
  actor Admin as Administrator
  participant H as Hydda One
  participant S as Your system
  Admin->>H: creates the integration
  H-->>Admin: client id and client secret
  Admin->>H: saves the organization settings
  Admin->>H: assigns the Billing Integration role
  Admin-->>S: hands over the client id and secret
  S->>H: POST /oauth/token
  H-->>S: access token
  S->>H: GET /v1/integrations/configurations
  H-->>S: one configuration, pending
  S->>H: POST /v1/integrations/configurations/{id}/ready
  Note over H,S: The billing queues are open
  S->>H: GET /v1/billing/send-queue
```

The first half happens once, in the admin console. The second half is what your system does every time it starts.

## Before you start

- **An organization administrator.** Only an administrator of the organization can create an integration and assign its role.
- **The right environment.** Build against the development environment first. Its admin console is `admin.dev.hydda.one`, its identity host `idp.dev.hydda.one` and its API host `api.dev.hydda.one`. Production uses `admin.hydda.one`, `idp.hydda.one` and `api.hydda.one`. An integration and its secret exist in one environment only, so you do the steps below once in each.
- **No other invoicing integration.** An organization has one invoicing integration at a time. If another one delivers its invoices today, see [Take over from a connector](#take-over-from-a-connector).

## In the admin console

1. **Create the integration**

    Go to **Settings**, then **Integrations**, and choose **Create your own integration**.

    | Field | What to enter |
    | --- | --- |
    | **Name** | What operators will see, such as the name of your ERP. |
    | **What it fills** | **Invoicing**. It cannot be changed later. |
    | **Capabilities** | **Sending** is always on. Switch on **Invoice review** only if your system will check each invoice before it is created. See [Choose your capabilities](#choose-your-capabilities). |
    | **Setup address** | Leave it empty. |

    Choose **Create and install**. This creates the integration and installs it in your organization in one step.

2. **Store the client id and the client secret**

    The console now shows a **Client ID** and a **Client secret**. The secret starts with `everest_sk_`. This is the only time it is shown, so store it in your secret manager before you close the panel.

    If you lose it, issue a new one. See [Rotate the secret](#rotate-the-secret).

3. **Switch it on for the organization**

    Open the integration under **Installed**. In **Organization settings**, choose **Configure**, then **Save**.

    Your integration has no settings to fill in here. Saving is what switches it on. The row now shows **Pending**: Hydda One is waiting for your system to report that it works.

4. **Assign the role**

    On the same row, follow **Assign the role to this application**. It opens the integration's application. Under **Roles**, grant **Billing Integration**.

    Without the role, your system can sign in but every billing route answers `403`.

The administrator's part is done. Everything below is your system's.

## In your system

### 1. Get a token

Exchange the client id and secret for an access token. It lives for 600 seconds and comes with no refresh token, so request a new one before it expires.

```bash
curl https://idp.dev.hydda.one/oauth/token \
  -u "$CLIENT_ID:$CLIENT_SECRET" \
  -d grant_type=client_credentials
```

```json
{ "access_token": "eyJ…", "token_type": "Bearer", "expires_in": 600 }
```

Send it on every call as `Authorization: Bearer <access_token>`. [Authentication](/guides/authentication) has the details and the errors.

### 2. Read your configuration

```bash
curl https://api.dev.hydda.one/v1/integrations/configurations \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

```json
{
  "configurations": [
    {
      "id": "0b9f3c1e-5a4d-4c2b-8e7f-6a5b4c3d2e1f",
      "operationalContextId": "7d1e2f3a-4b5c-4d6e-8f70-1a2b3c4d5e6f",
      "level": "organization",
      "values": {},
      "secrets": {},
      "status": "pending",
      "manifestVersion": 1,
      "updatedAt": "2026-11-16T09:12:44.000Z"
    }
  ]
}
```

You get one configuration, at the `organization` level. `values` and `secrets` are empty, because an integration of your own has no settings in Hydda One.

An empty list means the administrator has not saved the organization settings yet. A `403` means the integration is disabled, or the token does not belong to the integration's application.

### 3. Report ready

Check that your side works: that you can reach your ERP with your own credentials, for example. Then report it.

```bash
curl -X POST "https://api.dev.hydda.one/v1/integrations/configurations/$CONFIGURATION_ID/ready" \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

The answer is `204`. The row in the admin console turns to **Ready**, and the billing queues open.

If your side cannot work, report that instead. The administrator sees your `code` and `reason` on the row, so write the reason for them and never put a secret in it.

```bash
curl -X POST "https://api.dev.hydda.one/v1/integrations/configurations/$CONFIGURATION_ID/failed" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "code": "erp_unreachable", "reason": "The ERP did not answer. Check that the API user is active." }'
```

Both reports are safe to repeat. Run steps 2 and 3 every time your system starts: if the status is `pending`, check and report again.

### 4. Map business contexts to your companies

Every invoice names the business context it belongs to, in `businessContextId`. Your system decides which ERP account that means. Read the business contexts once, and keep the mapping in your own configuration.

```bash
curl "https://idp.dev.hydda.one/v1/operational-contexts?types=coworking&types=residential&types=facility_management" \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

Note the host: this one route is on the identity host. [Organizations and contexts](/guides/concepts/organizations-and-contexts) explains what a business context is.

### 5. Do the work

Read a page of the send queue, issue each invoice in your ERP, and report the whole page in one request. Repeat until the queue is empty.

```bash
curl "https://api.dev.hydda.one/v1/billing/send-queue?limit=200" \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

A page holds up to 200 invoices, and a report takes up to 200 items. The answer to a report has one result for each item, so one refused invoice does not stop the others.

```bash
curl -X POST https://api.dev.hydda.one/v1/billing/batch/report-sent \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "items": [
      {
        "invoiceId": "3f1c2a9e-7b64-4d0f-9a1e-5c8d7e6f4b21",
        "externalReference": "erp-invoice-88213",
        "issuedInvoiceNumber": "2026-000317",
        "issuedInvoiceDate": "2026-11-16",
        "dueDate": "2026-12-16",
        "issuedTotalGrossMinorUnits": 1250000
      }
    ]
  }'
```

The [Billing guide](/guides/surfaces/billing) describes every queue and report. [Invoicing objects](/guides/concepts/invoicing) explains the fields on each item.

## A minimal worker

This is the whole loop in TypeScript, on Node.js 22 or later with no dependencies. `issueInErp` and `erpAccountFor` are yours to write. `issueInErp` returns the issued document, or `{ refused: "…" }` when your ERP will not take the invoice.

```ts worker.ts
const IDP = "https://idp.dev.hydda.one";
const API = "https://api.dev.hydda.one";

const sleep = (milliseconds: number) => new Promise((resolve) => setTimeout(resolve, milliseconds));

let token = { value: "", expiresAt: 0 };

async function accessToken(): Promise<string> {
  if (Date.now() < token.expiresAt - 60_000) return token.value;
  const basic = Buffer.from(`${process.env.CLIENT_ID}:${process.env.CLIENT_SECRET}`).toString("base64");
  const response = await fetch(`${IDP}/oauth/token`, {
    method: "POST",
    headers: { Authorization: `Basic ${basic}`, "Content-Type": "application/x-www-form-urlencoded" },
    body: "grant_type=client_credentials",
  });
  if (!response.ok) throw new Error(`token request failed: ${response.status}`);
  const body = await response.json();
  token = { value: body.access_token, expiresAt: Date.now() + body.expires_in * 1000 };
  return token.value;
}

async function call(method: string, path: string, body?: unknown): Promise<any> {
  for (;;) {
    const response = await fetch(`${API}${path}`, {
      method,
      headers: {
        Authorization: `Bearer ${await accessToken()}`,
        ...(body === undefined ? {} : { "Content-Type": "application/json" }),
      },
      body: body === undefined ? undefined : JSON.stringify(body),
    });
    if (response.status === 429) {
      await sleep(Number(response.headers.get("Retry-After") ?? 10) * 1000);
      continue;
    }
    if (!response.ok) {
      const problem = await response.json().catch(() => ({}));
      throw new Error(`${method} ${path}: ${response.status} ${problem.code ?? ""}`);
    }
    return response.status === 204 ? undefined : response.json();
  }
}

async function reportReady(): Promise<void> {
  const { configurations } = await call("GET", "/v1/integrations/configurations");
  for (const configuration of configurations) {
    if (configuration.status !== "ready") {
      await call("POST", `/v1/integrations/configurations/${configuration.id}/ready`);
    }
  }
}

async function report(path: string, items: { invoiceId: string }[]): Promise<void> {
  if (items.length === 0) return;
  const { results } = await call("POST", path, { items });
  results.forEach((result: any, index: number) => {
    if (result.status >= 400) {
      const { code, detail } = result.problem;
      console.error(`${path} ${items[index].invoiceId}: ${result.status} ${code ?? detail}`);
    }
  });
}

async function sendInvoices(): Promise<void> {
  const tried = new Set<string>();
  for (;;) {
    const { items } = await call("GET", "/v1/billing/send-queue?limit=200");
    const page = items.filter((item: any) => !tried.has(item.invoice.id));
    if (page.length === 0) return;

    const sent = [];
    const failed = [];
    for (const item of page) {
      const { invoice } = item;
      tried.add(invoice.id);
      const account = invoice.businessContextId && erpAccountFor(invoice.businessContextId);
      if (!account) {
        failed.push({
          invoiceId: invoice.id,
          reason: "No ERP account is mapped to this invoice's business context.",
        });
        continue;
      }
      const issued = await issueInErp(account, item).catch((error) => {
        console.error(`invoice ${invoice.id} was not issued`, error);
      });
      if (!issued) continue;
      if ("refused" in issued) {
        failed.push({ invoiceId: invoice.id, reason: issued.refused });
        continue;
      }
      sent.push({
        invoiceId: invoice.id,
        externalReference: issued.id,
        issuedInvoiceNumber: issued.number,
        issuedInvoiceDate: issued.invoiceDate,
        dueDate: issued.dueDate,
        issuedTotalGrossMinorUnits: issued.totalGrossMinorUnits,
      });
    }
    await report("/v1/billing/batch/report-sent", sent);
    await report("/v1/billing/batch/report-failed", failed);
  }
}

await reportReady();
for (;;) {
  await sendInvoices().catch((error) => console.error(error));
  await sleep(60_000);
}
```

What the sketch does, and what it leaves to you:

- **It reports a page in one request.** Each pass of the loop reads up to 200 invoices and sends at most two batches: the invoices it issued, and the ones your ERP refused. It sends one batch at a time, and waits when the answer is `429`.
- **It stops on a queue it cannot empty.** An invoice whose report was refused can still be on the queue. `tried` keeps the loop from reading the same invoices for ever. They come back on the next run, a minute later.
- **It reports failed only what your ERP refuses.** An invoice reported failed is gone: an operator has to correct the material and build a new one. When `issueInErp` throws, for a timeout for example, the sketch leaves the invoice on the queue and tries again on the next run.
- **Issue each invoice once.** Reading a queue claims nothing. If your system issues an invoice and stops before it reports, it gets the same item again. Make `issueInErp` look the invoice up by its Hydda One `id` first, and return the existing document when there is one.
- **Act on refused items.** The sketch only logs a refused item. Each result carries the `code` that says why. See [Errors to handle](/guides/surfaces/billing#errors-to-handle).

Payments, write-offs and deleted invoices follow the same pattern on their own batch routes. See [Report in batches](/guides/surfaces/billing#report-in-batches).

## Choose your capabilities

| Capability | Name in the admin console | What your system must do |
| --- | --- | --- |
| `sending` | Sending | Poll the send queue and the withdrawal queue. Report the invoices sent or failed, a page at a time, then report their payments. |
| `basisVerification` | Invoice review | Also poll the verification queue, and pass or reject each proposal. |

Switch on **Invoice review** only if your system will rule on every proposal. With it on, no invoice is created until your system passes its proposal, so a system that never polls the verification queue stops all invoicing.

An administrator can change the capabilities later with **Edit** on the integration. The change takes effect when the administrator then chooses **Change** and **Save** on the organization settings. The configuration returns to `pending`, and your system reports `ready` again.

A route for a capability you did not switch on answers `BILLING_INTEGRATION_GATE_NOT_DECLARED`.

## Keep it running

### Report when it breaks

Report `failed` whenever your system stops working, not only when it starts:

```bash
curl -X POST "https://api.dev.hydda.one/v1/integrations/configurations/$CONFIGURATION_ID/failed" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "code": "erp_credentials_expired", "reason": "The ERP rejected our API key. Create a new key in the ERP." }'
```

The admin console then shows the row as **Failed** with your `reason`. Approved invoices stay on the send queue, so nothing is lost while your system is down.

Report `ready` when it works again.

### Rotate the secret

An application can have two active secrets at a time, so you can change the secret without downtime:

1. An administrator opens the application under **Settings**, then **Applications**, and chooses **Issue new secret**.
2. You deploy the new secret.
3. The administrator revokes the old one.

A revoked secret gets no new tokens. A token already issued keeps working until it expires, at most 600 seconds later.

### Stop it

To cut off your system's access, an administrator disables its **application**, under **Settings**, then **Applications**. It then gets no new tokens, and a token already issued stops working within 600 seconds. Enabling the application again restores its access, with its roles and secrets as they were.

To hand invoicing over to another integration, an administrator chooses **Uninstall** on your integration. That removes its configuration and frees the invoicing point. Until another integration is ready, invoices wait at approved.

## Take over from a connector

Hydda runs connectors of its own, such as Payer for invoicing. If one fills the invoicing point today, yours cannot until it is removed:

1. Build and test your integration in the development environment.
2. In production, an administrator chooses **Uninstall** on the connector. The invoicing point is now free.
3. The administrator creates your integration, as in [In the admin console](#in-the-admin-console), and your system reports `ready`.

Between steps 2 and 3 approved invoices stay approved. They reach the send queue once your integration is `ready`.

Invoices the connector reported sent keep the connector's `externalReference`. To report payments on them, name each one by its `invoiceId`.

## When something does not work

| You see | What it means | What to do |
| --- | --- | --- |
| `401` with `invalid_client` from the token endpoint | The client id or secret is wrong or revoked, the application is disabled, or you are using one environment's credentials in the other. | Check the credentials and the host. |
| `403` from `/v1/integrations/configurations` | The integration is disabled, or the token is not from the integration's own application. | Enable the integration, or use the client id it was created with. |
| An empty `configurations` list | The organization settings are not saved yet. | Do step 3 of the admin console steps. |
| `403` from `/v1/billing` | The application does not hold `Billing Integration`. | Do step 4 of the admin console steps. |
| `400` with `BILLING_INTEGRATION_NOT_CONFIGURED` | No configuration is `ready`. | Report `ready`. |
| `400` with `BILLING_INTEGRATION_GATE_NOT_DECLARED` | The route belongs to a capability that is not switched on. | Switch on **Invoice review**, or stop calling the route. |
| An empty send queue | No invoice is approved with a requested invoice date of today or earlier. | Have an operator approve an invoice in the development environment. |
| The administrator sees "Another integration already handles this here" | Another integration fills the invoicing point. | Remove that integration's configuration first. |

## The same for contract signing

To build your own signing integration, follow the same steps with these differences:

| Step | For contract signing |
| --- | --- |
| **What it fills** | **Contract signing**. |
| Switch it on | Under **Business contexts**, choose **Configure** and **Save** for each business context that will sign through your system. |
| Assign the role | Grant **Signing Integration** once for each of those business contexts. |
| Read your configuration | You get one configuration for each business context, with `level` `business_context`. Report each one `ready`. |
| Do the work | Follow the [Signing guide](/guides/surfaces/signing). Each item's `businessContextId` names the business context to sign for. |

## Next

**[Billing API guide](/guides/surfaces/billing)**

Every queue and batch report, with the rules for retries.

**[Connect on your own page](/guides/integrations/setup-address)**

Optional: send the administrator to a page of yours to finish the connection.
