---
title: Zefix (Switzerland)
url: https://documentation.cluedin.net/govern/rest-api-enricher-samples/zefix-switzerland
content_type: reference
section: Govern & improve > REST API enricher samples
---

# Zefix (Switzerland)

> reference: Facts, options, APIs.

This example looks up an organization's Swiss business identification number (UID, for example `CHE-105.909.036`) in [Zefix](https://www.zefix.admin.ch/), the Central Business Name Index of the Swiss cantonal commercial registers, by using the [Zefix PublicREST API](https://www.zefix.admin.ch/ZefixPublicREST/swagger-ui/index.html). For each golden record it stores the registered name and its other language versions, legal form, status, legal seat, canton, registered address, purpose, nominal capital, the date of the last publication in the Swiss Official Gazette of Commerce (SOGC), and a link to the cantonal register excerpt.

**Enricher version:** V2  
**API key:** your Zefix PublicREST user name and password, entered as `username:password`. Credentials are free; request them from the Federal Registry of Commerce by email to [zefix@bj.admin.ch](mailto:zefix@bj.admin.ch).

To set up the enricher, see [Add REST API enricher](https://documentation.cluedin.net/govern/enrichment/rest-api.md#add-rest-api-enricher), then use the settings and script on this page.

## Settings

- **Accepted Business Domain** – `/Organization`, or the business domain that holds your companies.

- **Version** – V2 (recommended).

- **API Key** – your Zefix PublicREST user name and password, separated by a colon: `username:password`. Everything after the first colon is the password. The script sends them with HTTP Basic authentication. If the field is empty or has no colon, the script adds nothing and doesn't call Zefix.

- **Filters** – we recommend a rule that only accepts golden records where `organization.uid` has a value. Otherwise, every record without a UID is listed on the enricher's **Logs** tab as having returned no results.

## Vocabulary and Properties

```
organization.uid
```

`organization.uid` holds the UID. The Swiss VAT number (for example `CHE-105.909.036 MWST`) works too, because it is the UID with a suffix. If your data uses another vocabulary key, change this field and the `UID_KEY` value at the top of the script.

## Request and response

**Base URL:** `https://www.zefix.admin.ch/ZefixPublicREST/api/v1`  
**Endpoint:** `GET /company/uid/{uid}`, with the UID written without separators, for example `CHE105909036`  
**Authentication:** HTTP Basic authentication with your Zefix PublicREST user name and password  
**Rate limits:** Zefix doesn't publish a rate limit. Keep the cache on and avoid enriching very large numbers of golden records at once.  
**Licence:** the data is open government data; the terms require you to name the source (Zefix).

The script sends one request per golden record:

```http
GET https://www.zefix.admin.ch/ZefixPublicREST/api/v1/company/uid/CHE105909036
Authorization: Basic <base64 of username:password>
Accept: application/json
```

Shortened response. The field names come from the `CompanyFull` schema in the API's [OpenAPI document](https://www.zefix.admin.ch/ZefixPublicREST/v3/api-docs); the values are illustrative (taken from Zefix's public web search), because the API couldn't be called with real credentials while writing this example. A company that is registered with more than one head office has one entry for each:

```json
[
  {
    "name": "Nestlé S.A.",
    "ehraid": 126288,
    "uid": "CHE105909036",
    "chid": "CH55000672935",
    "legalSeatId": 5890,
    "legalSeat": "Vevey",
    "legalForm": {
      "id": 3,
      "uid": "0106",
      "name": { "de": "Aktiengesellschaft", "fr": "Société anonyme", "it": "Società anonima", "en": "Corporation" }
    },
    "status": "ACTIVE",
    "sogcDate": "2026-12-01",
    "translation": ["Nestlé AG", "Nestlé Ltd."],
    "purpose": "La participation à des entreprises industrielles, de services, commerciales et financières en Suisse et à l'étranger, …",
    "address": { "organisation": "Nestlé S.A.", "street": "Avenue Nestlé", "houseNumber": "55", "city": "Vevey", "swissZipCode": "1800" },
    "canton": "VD",
    "cantonalExcerptWeb": "https://prestations.vd.ch/pub/101266/extract?lang=FR&companyOfsUid=CHE-105.909.036"
  },
  {
    "name": "Nestlé AG",
    "ehraid": 126286,
    "uid": "CHE105909036",
    "legalSeat": "Cham",
    "status": "ACTIVE",
    "canton": "ZG"
  }
]
```

## Properties added by the enricher

| Property | Response field | Example |
| -------- | -------------- | ------- |
| `zefix.uid` | the UID that was looked up, as `CHE-###.###.###` | `CHE-105.909.036` |
| `zefix.name` | `name` | `Nestlé S.A.` |
| `zefix.nameTranslations` | `translation`, other than `name`, separated by `; ` | `Nestlé AG; Nestlé Ltd.` |
| `zefix.legalForm` | `legalForm.name` in the language set by `LANGUAGE` (English by default) | `Corporation` |
| `zefix.legalFormCode` | `legalForm.uid` (eCH-0097 code) | `0106` |
| `zefix.status` | `status`: `ACTIVE`, `BEING_CANCELLED` (in liquidation) or `CANCELLED` (deleted) | `ACTIVE` |
| `zefix.legalSeat` | `legalSeat` | `Vevey` |
| `zefix.canton` | `canton` | `VD` |
| `zefix.address` | `address`, on one line | `Avenue Nestlé 55, 1800 Vevey` |
| `zefix.city` | `address.city` | `Vevey` |
| `zefix.postalCode` | `address.swissZipCode` | `1800` |
| `zefix.purpose` | `purpose`, in the language of the register entry | `La participation à des entreprises …` |
| `zefix.capital` | `capitalNominal` and `capitalCurrency` | `100000 CHF` |
| `zefix.chid` | `chid` (former commercial register number) | `CH55000672935` |
| `zefix.ehraid` | `ehraid` (internal Zefix ID) | `126288` |
| `zefix.lastPublicationDate` | `sogcDate`, as `YYYY-MM-DD` | `2026-12-01` |
| `zefix.deletionDate` | `deletionDate`, as `YYYY-MM-DD` | `2024-03-09` |
| `zefix.excerptUrl` | `cantonalExcerptWeb` | `https://prestations.vd.ch/pub/101266/extract?…` |

A property is added only when Zefix returns a value for it. When the UID has several entries, the script uses the first active one, or the first one if none is active.

If the enricher has a **Preview** tab, the results appear there first. To add them to golden records, go to the **Map** tab, select **Map Data**, and choose **Auto Mapping**. Select the business domain, enter a new vocabulary named `Zefix` with the key prefix `zefix`, and then create the mapping. Auto mapping also uses `name` as the golden record name, so remove that from the mapping if you want to keep your existing names. Then process the data on the **Process** tab. If the enricher has no **Preview** tab, the properties are added to the golden record as soon as it is enriched.

## How the script handles input and errors

- The `CHE` prefix, dashes, dots, spaces, and a VAT suffix (`MWST`, `TVA`, `IVA`) are removed, so `CHE-105.909.036 MWST` is looked up as `CHE105909036`. A 9-digit number without the prefix is accepted too. The check digit is verified, so golden records without a valid UID are skipped without calling Zefix.

- If no company is registered with the UID (HTTP 404), the request is invalid (HTTP 400), or Zefix returns another error, the script logs the reason and adds nothing.

- If Zefix rejects the credentials (HTTP 401 or 403), the script throws an error, so the golden record is listed on the **Logs** tab with a message to check the **API Key** field.

- If Zefix reports that it is too busy (HTTP 429 or 503), the script throws an error that makes the enricher try the golden record again later.

- Successful results are cached for 24 hours per UID. To change this, edit `CACHE_MILLISECONDS` in the script.

## Testing the enricher

- **Test connection** checks only that the script runs. It doesn't call Zefix.

- To try the setup, create a golden record with `organization.uid` set to `CHE-105.909.036` (Nestlé S.A.).

- Zefix also has an integration (test) environment. If the Federal Registry of Commerce gave you credentials for it, temporarily change `ZEFIX_URL` in the script to `https://www.zefixintg.admin.ch/ZefixPublicREST/api/v1/company/uid/`.

- The error handling on this page was checked against the live Zefix service with placeholder credentials (it answers HTTP 401). A successful lookup couldn't be run while writing this example, so the example values are illustrative.

## Limitations

- Zefix is an index of the cantonal commercial registers. Only entities entered in a commercial register are found; sole proprietorships and associations that aren't registered don't have a Zefix entry.

- The purpose is returned in the language of the register entry (German, French or Italian).

- Board members, signatories and auditors aren't added. SOGC publications, branch offices and takeovers are in the response but aren't added either.

## Process script

```javascript
// REST API enricher (V2) - Swiss company lookup with Zefix
//
// Looks up a golden record's Swiss business identification number (UID, for example
// CHE-105.909.036) in Zefix, the Central Business Name Index of the Swiss commercial registers,
// by using the Zefix PublicREST API (https://www.zefix.admin.ch/ZefixPublicREST/), and adds the
// result to the golden record as zefix.* properties:
//
//   zefix.uid                 UID that was looked up, formatted as CHE-###.###.###
//   zefix.name                registered business name
//   zefix.nameTranslations    other language versions of the name, separated by "; "
//   zefix.legalForm           legal form, for example Corporation (in LANGUAGE)
//   zefix.legalFormCode       legal form code (eCH-0097), for example 0106
//   zefix.status              ACTIVE, BEING_CANCELLED (in liquidation) or CANCELLED (deleted)
//   zefix.legalSeat           legal seat (political municipality)
//   zefix.canton              canton abbreviation, for example VD
//   zefix.address             registered address on one line
//   zefix.city                town of the address
//   zefix.postalCode          Swiss postcode of the address
//   zefix.purpose             purpose, as registered (in the language of the register entry)
//   zefix.capital             nominal capital with currency, for example 100000 CHF
//   zefix.chid                CH-ID, the former 13-character commercial register number
//   zefix.ehraid              internal Zefix company ID
//   zefix.lastPublicationDate date of the last publication in the Swiss Official Gazette of Commerce (YYYY-MM-DD)
//   zefix.deletionDate        date the company was deleted from the register (YYYY-MM-DD)
//   zefix.excerptUrl          link to the cantonal commercial register excerpt
//
// Needs Zefix PublicREST credentials (free, issued on request by the Federal Registry of
// Commerce). Enter "username:password" in the enricher's API Key field. See README.md next to
// this file for the enricher settings.
//
// A record gets no result (nothing is stored) when it has no valid UID, when no company is
// registered with it, or when the API can't answer. Missing credentials make no call; rejected
// credentials fail the record with an error that says so.

// ---- Settings -------------------------------------------------------------------------

// Vocabulary key to read. Add the same key to the Vocabulary and Properties field.
const UID_KEY = "organization.uid";

// Use https://www.zefixintg.admin.ch/ZefixPublicREST/api/v1/company/uid/ to try the setup in
// the Zefix integration (test) environment first, if you have credentials for it.
const ZEFIX_URL = "https://www.zefix.admin.ch/ZefixPublicREST/api/v1/company/uid/";

// Language of the legal form name: en, de, fr or it. Other languages are used when it's missing.
const LANGUAGE = "en";

// The {APIKey} placeholder is replaced with the API Key field value ("username:password").
const API_KEY = "{APIKey}";

// How long to reuse an answer for the same UID. 0 turns caching off.
const CACHE_MILLISECONDS = 24 * 60 * 60 * 1000;

// ---- Script ---------------------------------------------------------------------------

function getValue(key) {
  // A plain loop rather than vocabularies.find(...): vocabularies is a .NET list, and when
  // .find is called from inside a function, later calls return the first call's match.
  const items = vocabularies || [];
  for (let i = 0; i < items.length; i++) {
    if (items[i].Key === key) {
      const value = items[i].Value;
      return value === null || value === undefined ? "" : String(value).trim();
    }
  }
  return "";
}

// Accepts "CHE-105.909.036", "CHE105909036", "CHE-105.909.036 MWST" (the VAT number form) and
// "105909036". Returns the 9 digits, or null when it isn't a valid UID (MOD11 check digit).
function parseUid(raw) {
  const text = raw.toUpperCase().replace(/^CHE/, "").replace(/(MWST|TVA|IVA|VAT)$/, "");
  if (/[A-Z]/.test(text)) {
    return null;
  }
  const digits = text.replace(/[^0-9]/g, "");
  if (digits.length !== 9) {
    return null;
  }
  const weights = [5, 4, 3, 2, 7, 6, 5, 4];
  let sum = 0;
  for (let i = 0; i < 8; i++) {
    sum += Number(digits.charAt(i)) * weights[i];
  }
  const remainder = sum % 11;
  const checkDigit = remainder === 0 ? 0 : 11 - remainder;
  return checkDigit !== 10 && checkDigit === Number(digits.charAt(8)) ? digits : null;
}

function formatUid(digits) {
  return `CHE-${digits.substring(0, 3)}.${digits.substring(3, 6)}.${digits.substring(6, 9)}`;
}

// "username:password" from the API Key field as a Basic authorization header value, or null.
function authorization() {
  const value = String(API_KEY || "").trim();
  const separator = value.indexOf(":");
  if (separator <= 0 || separator === value.length - 1) {
    return null;
  }
  return "Basic " + stringEncoder.toBase64(value);
}

function clean(value) {
  if (value === null || value === undefined) {
    return null;
  }
  const text = String(value).replace(/\s+/g, " ").trim();
  return text === "" ? null : text;
}

function parseJson(text) {
  try {
    return JSON.parse(text);
  } catch (e) {
    return null;
  }
}

function dateOnly(value) {
  const text = clean(value);
  return text && /^\d{4}-\d{2}-\d{2}/.test(text) ? text.substring(0, 10) : null;
}

// A translated text ({ de, fr, it, en }) in LANGUAGE, or in the first other language that has it.
function translated(value) {
  if (!value) {
    return null;
  }
  if (typeof value === "string") {
    return clean(value);
  }
  const languages = [LANGUAGE, "en", "de", "fr", "it"];
  for (let i = 0; i < languages.length; i++) {
    const text = clean(value[languages[i]]);
    if (text) {
      return text;
    }
  }
  return null;
}

function formatAddress(address) {
  if (!address) {
    return null;
  }
  const street = [clean(address.street), clean(address.houseNumber)].filter((x) => !!x).join(" ");
  const town = [clean(address.swissZipCode), clean(address.city) || clean(address.town)].filter((x) => !!x).join(" ");
  const parts = [clean(address.careOf), street, clean(address.addon), clean(address.poBox), town].filter((x) => !!x);
  return parts.length > 0 ? parts.join(", ") : null;
}

// The UID lookup returns a list (a company registered with several head offices has one entry
// for each), and sometimes a single object. Returns the active entry, or else the first one.
function pickCompany(body) {
  const list = Array.isArray(body) ? body : body && typeof body === "object" ? [body] : [];
  let first = null;
  for (let i = 0; i < list.length; i++) {
    const company = list[i];
    if (company && clean(company.name)) {
      if (company.status === "ACTIVE") {
        return company;
      }
      first = first || company;
    }
  }
  return first;
}

// Calls the API. Returns the company, or null when there's no answer to store.
function lookUp(uid, authorizationHeader) {
  const apiResponse = http.send({
    url: ZEFIX_URL + "CHE" + uid,
    method: "GET",
    headers: [
      { Key: "Authorization", Value: authorizationHeader },
      { Key: "Accept", Value: "application/json" },
    ],
  });

  const status = String(apiResponse.HttpStatus || "");
  const body = parseJson(apiResponse.Content);

  if (status === "TooManyRequests" || status === "ServiceUnavailable") {
    throw new Error(`TooManyRequests - Zefix is busy (HTTP ${status}), the record will be retried`);
  }

  if (status === "Unauthorized" || status === "Forbidden") {
    throw new Error(`Zefix rejected the credentials in the API Key field (HTTP ${status}). Enter your Zefix PublicREST "username:password".`);
  }

  const company = status === "OK" ? pickCompany(body) : null;
  if (company) {
    return company;
  }

  // 404 NOT_FOUND: no company is registered with this UID.
  const error = body && body.error ? `${body.error.type}: ${body.error.message}` : String(apiResponse.Content || "").substring(0, 200);
  log(`Zefix could not look up ${formatUid(uid)}. HTTP ${status}. ${error}`);
  return null;
}

function run() {
  const uid = parseUid(getValue(UID_KEY));
  if (!uid) {
    // No valid UID on this record (this is also what Test connection hits, because it passes
    // placeholder values instead of real ones).
    return [];
  }

  const authorizationHeader = authorization();
  if (!authorizationHeader) {
    log('No Zefix credentials. Enter "username:password" in the API Key field of the enricher.');
    return [];
  }

  const cacheKey = `zefix:${uid}`;
  const cached = CACHE_MILLISECONDS > 0 ? cache.get(cacheKey) : null;
  let company = cached ? parseJson(String(cached)) : null;

  if (!company) {
    company = lookUp(uid, authorizationHeader);
    if (!company) {
      return [];
    }
    if (CACHE_MILLISECONDS > 0) {
      cache.set(cacheKey, JSON.stringify(company), CACHE_MILLISECONDS);
    }
  }

  const name = clean(company.name);
  const translations = (Array.isArray(company.translation) ? company.translation : [])
    .map((x) => clean(x))
    .filter((x) => !!x && x !== name);
  const legalForm = company.legalForm || {};
  const address = company.address || null;
  const capital = clean(company.capitalNominal);

  const data = {
    "zefix.uid": formatUid(uid),
    "zefix.name": name,
    "zefix.nameTranslations": translations.length > 0 ? translations.join("; ") : null,
    "zefix.legalForm": translated(legalForm.name),
    "zefix.legalFormCode": clean(legalForm.uid),
    "zefix.status": clean(company.status),
    "zefix.legalSeat": clean(company.legalSeat),
    "zefix.canton": clean(company.canton),
    "zefix.address": formatAddress(address),
    "zefix.city": address ? clean(address.city) || clean(address.town) : null,
    "zefix.postalCode": address ? clean(address.swissZipCode) : null,
    "zefix.purpose": clean(company.purpose),
    "zefix.capital": capital ? [capital, clean(company.capitalCurrency)].filter((x) => !!x).join(" ") : null,
    "zefix.chid": clean(company.chid),
    "zefix.ehraid": clean(company.ehraid),
    "zefix.lastPublicationDate": dateOnly(company.sogcDate),
    "zefix.deletionDate": dateOnly(company.deletionDate),
    "zefix.excerptUrl": clean(company.cantonalExcerptWeb),
  };

  // Leave out values Zefix didn't return, so they don't overwrite existing data with blanks.
  Object.keys(data).forEach((key) => {
    if (data[key] === null) {
      delete data[key];
    }
  });

  return [{ Data: data, Score: 100 }];
}

response = JSON.stringify(run());
```

Up: [REST API enricher samples](https://documentation.cluedin.net/govern/rest-api-enricher-samples.md)
