---
title: Recherche d'entreprises (France)
url: http://0.0.0.0:4000/govern/rest-api-enricher-samples/recherche-entreprises-france
content_type: reference
section: Govern & improve > REST API enricher samples
---

# Recherche d'entreprises (France)

> reference: Facts, options, APIs.

This example looks up an organization's French SIREN number in the Sirene directory of companies (kept by INSEE, combined with the national company register) by using the French government's open [Recherche d'entreprises API](https://recherche-entreprises.api.gouv.fr/docs/). For each golden record it stores the registered name and acronym, VAT number, legal form code, main activity code (NAF), company size category, number of employees, creation and closure dates, administrative status, and the head office SIRET and address. No API key is needed.

**Enricher version:** V2  
**API key:** not needed

To set up the enricher, see [Add REST API enricher](http://0.0.0.0:4000/govern/enrichment/rest-api#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** – leave empty.

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

## Vocabulary and Properties

```
organization.siren
```

`organization.siren` holds the 9-digit SIREN number. A 14-digit SIRET number or a French VAT number (for example `FR59542051180`) in this key also works, because both contain the SIREN. If your data uses another vocabulary key, change this field and the `SIREN_KEY` value at the top of the script.

## Request and response

**Base URL:** `https://recherche-entreprises.api.gouv.fr`  
**Endpoint:** `GET /search?q={siren}&page=1&per_page=5`  
**Authentication:** none  
**Rate limit:** at most 7 requests per second per IP address, and 30 requests per second per network (ASN), according to the [API documentation](https://recherche-entreprises.api.gouv.fr/docs/). Servers in public clouds share the ASN limit, so expect some `429` responses there.

The script sends one request per golden record:

```http
GET https://recherche-entreprises.api.gouv.fr/search?q=542051180&page=1&per_page=5
Accept: application/json
```

Shortened response:

```json
{
  "results": [
    {
      "siren": "542051180",
      "nom_complet": "TOTALENERGIES SE (TOTALENERGIE SE)",
      "nom_raison_sociale": "TOTALENERGIES SE",
      "sigle": null,
      "nombre_etablissements": 17,
      "nombre_etablissements_ouverts": 4,
      "siege": {
        "activite_principale": "70.10Z",
        "adresse": "LA DEFENSE 6 2 PLACE JEAN MILLIER 92400 COURBEVOIE",
        "code_postal": "92400",
        "libelle_commune": "COURBEVOIE",
        "est_siege": true,
        "etat_administratif": "A",
        "siret": "54205118000066"
      },
      "activite_principale": "70.10Z",
      "categorie_entreprise": "GE",
      "date_creation": "1954-01-01",
      "date_fermeture": null,
      "etat_administratif": "A",
      "nature_juridique": "5800",
      "tranche_effectif_salarie": "51",
      "tva": ["FR59542051180"]
    }
  ],
  "total_results": 1,
  "page": 1,
  "per_page": 5,
  "total_pages": 1
}
```

## Properties added by the enricher

| Property | Response field | Example |
| -------- | -------------- | ------- |
| `sirene.siren` | `siren` | `542051180` |
| `sirene.name` | `nom_raison_sociale` (or `nom_complet` when there is no registered name) | `TOTALENERGIES SE` |
| `sirene.acronym` | `sigle` | `SG` |
| `sirene.vatNumber` | first entry of `tva` | `FR59542051180` |
| `sirene.legalFormCode` | `nature_juridique` (INSEE legal form code) | `5800` |
| `sirene.activityCode` | `activite_principale` (NAF code) | `70.10Z` |
| `sirene.companyCategory` | `categorie_entreprise`: `PME`, `ETI` or `GE` | `GE` |
| `sirene.employeeRange` | `tranche_effectif_salarie`, as a range of employees | `2000-4999` |
| `sirene.creationDate` | `date_creation` | `1954-01-01` |
| `sirene.closureDate` | `date_fermeture` | `1984-12-25` |
| `sirene.status` | `etat_administratif`: `Active` (`A`) or `Ceased` (`C`) | `Active` |
| `sirene.headOfficeSiret` | `siege.siret` | `54205118000066` |
| `sirene.headOfficeAddress` | `siege.adresse` | `LA DEFENSE 6 2 PLACE JEAN MILLIER 92400 COURBEVOIE` |
| `sirene.postalCode` | `siege.code_postal` | `92400` |
| `sirene.city` | `siege.libelle_commune` | `COURBEVOIE` |
| `sirene.openEstablishments` | `nombre_etablissements_ouverts` | `4` |

A property is added only when the register returns a value for it. Values that the company has asked to keep private (returned as `[PROTÉGÉ]`) and the placeholder creation date `1900-01-01` aren't added.

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 `Sirene` with the key prefix `sirene`, 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

- Spaces, dots, and dashes are removed, so `542 051 180` is looked up as `542051180`. A SIRET number (14 digits) is looked up by its first 9 digits, and a French VAT number (`FR` followed by a 2-character key and the SIREN) by its last 9 digits. The SIREN must pass the Luhn check digit test (La Poste's `356000000` is the one accepted exception). Golden records without a valid SIREN are skipped without calling the API.

- The API is a search, so the script only uses a result whose `siren` is exactly the number that was looked up and that has a name. If there is no such result, the request is invalid (HTTP 400), or the API returns another error, the script logs the reason and adds nothing.

- A company that has ceased trading is still returned. The script adds `sirene.status` = `Ceased` and `sirene.closureDate`.

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

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

## Testing the enricher

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

- To try the setup, create a golden record with `organization.siren` set to `542051180` (TotalEnergies SE) or `356000000` (La Poste).

## Limitations

- The API doesn't return companies that have asked not to be listed (non-diffusible), and some values of other companies may be protected.

- For sole traders (entrepreneurs individuels), the registered name is the person's name. Make sure you have a lawful basis for storing it.

- Only codes are returned for the legal form and activity. Their labels are in INSEE's published lists ([legal forms](https://www.insee.fr/fr/information/2028129), [NAF](https://www.insee.fr/fr/information/2120875)).

- The script doesn't add the company's officers (`dirigeants`), the other establishments, or financial data, although the API returns some of them.

- The Recherche d'entreprises API is meant for searching. For the complete Sirene data, see INSEE's own Sirene API, which needs an account.

## Process script

```javascript
// REST API enricher (V2) - French company lookup with the Recherche d'entreprises API
//
// Looks up a golden record's SIREN number in the French register of companies (the Sirene
// directory kept by INSEE, combined with the national company register), using the open
// Recherche d'entreprises API run by the French government's digital agency (DINUM)
// (https://recherche-entreprises.api.gouv.fr/docs/), and adds the result to the golden record
// as sirene.* properties:
//
//   sirene.siren              9-digit SIREN number that was looked up
//   sirene.name               registered name (raison sociale)
//   sirene.acronym            acronym (sigle)
//   sirene.vatNumber          French VAT number, for example FR59542051180
//   sirene.legalFormCode      INSEE legal form code (catégorie juridique), for example 5599
//   sirene.activityCode       main activity code (NAF), for example 70.10Z
//   sirene.companyCategory    company size category: PME, ETI or GE
//   sirene.employeeRange      number of employees, as a range, for example 2000-4999
//   sirene.creationDate       date the company was created (YYYY-MM-DD)
//   sirene.closureDate        date the company ceased trading (YYYY-MM-DD)
//   sirene.status             Active or Ceased
//   sirene.headOfficeSiret    14-digit SIRET number of the head office
//   sirene.headOfficeAddress  head office address on one line
//   sirene.postalCode         postal code of the head office
//   sirene.city               city of the head office
//   sirene.openEstablishments number of open establishments
//
// No API key is needed. See README.md next to this file for the enricher settings.
//
// A record gets no result (nothing is stored) when it has no valid SIREN, when the SIREN isn't
// in the register (or the company has asked not to be listed), or when the API can't answer.

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

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

const RECHERCHE_ENTREPRISES_URL = "https://recherche-entreprises.api.gouv.fr/search";

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

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

// INSEE employee size bands (tranche d'effectif salarié)
const EMPLOYEE_RANGES = {
  "00": "0",
  "01": "1-2",
  "02": "3-5",
  "03": "6-9",
  "11": "10-19",
  "12": "20-49",
  "21": "50-99",
  "22": "100-199",
  "31": "200-249",
  "32": "250-499",
  "41": "500-999",
  "42": "1000-1999",
  "51": "2000-4999",
  "52": "5000-9999",
  "53": "10000+",
};

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 "";
}

function luhnValid(digits) {
  let sum = 0;
  for (let i = 0; i < digits.length; i++) {
    let digit = Number(digits.charAt(digits.length - 1 - i));
    if (i % 2 === 1) {
      digit *= 2;
      if (digit > 9) {
        digit -= 9;
      }
    }
    sum += digit;
  }
  return sum % 10 === 0;
}

// Accepts a SIREN ("542 051 180", "542051180"), a SIRET (14 digits, the SIREN is its first 9)
// or a French VAT number ("FR 59 542051180"). Returns the 9-digit SIREN, or null when the
// value isn't a valid SIREN (Luhn check digit; La Poste's 356000000 is the one exception).
function parseSiren(raw) {
  let text = raw.toUpperCase().replace(/[\s.\-]/g, "");
  if (/^FR[0-9A-Z]{2}\d{9}$/.test(text)) {
    text = text.substring(4);
  }
  if (!/^\d{9}$/.test(text) && !/^\d{14}$/.test(text)) {
    return null;
  }
  const siren = text.substring(0, 9);
  if (siren === "356000000") {
    return siren;
  }
  return luhnValid(siren) ? siren : null;
}

function clean(value) {
  if (value === null || value === undefined) {
    return null;
  }
  const text = String(value).replace(/\s+/g, " ").trim();
  // Values that the company has asked to keep private are returned as [PROTÉGÉ]
  return text === "" || text.indexOf("[PROTÉGÉ]") >= 0 ? null : text;
}

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

function dateOnly(value) {
  const text = clean(value);
  // 1900-01-01 is used when the creation date isn't known
  return text && text.substring(0, 10) !== "1900-01-01" ? text.substring(0, 10) : null;
}

// Calls the API. Returns the company, or null when there's no answer to store.
function lookUp(siren) {
  const apiResponse = http.send({
    url: `${RECHERCHE_ENTREPRISES_URL}?q=${siren}&page=1&per_page=5`,
    method: "GET",
    headers: [{ Key: "Accept", Value: "application/json" }],
  });

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

  if (status === "TooManyRequests") {
    throw new Error("TooManyRequests - the Recherche d'entreprises API is busy, the record will be retried");
  }

  if (status === "OK" && body && Array.isArray(body.results)) {
    // The search can also match other companies; only an exact SIREN match with a name counts.
    for (let i = 0; i < body.results.length; i++) {
      const company = body.results[i];
      if (company && company.siren === siren && clean(company.nom_raison_sociale || company.nom_complet)) {
        return company;
      }
    }
    log(`Recherche d'entreprises has no company with SIREN ${siren}.`);
    return null;
  }

  log(`Recherche d'entreprises could not look up ${siren}. HTTP ${status}. ${String(apiResponse.Content || "").substring(0, 200)}`);
  return null;
}

function toData(company) {
  const headOffice = company.siege || {};
  const vatNumbers = Array.isArray(company.tva) ? company.tva : [];
  const state = clean(company.etat_administratif);

  const data = {
    "sirene.siren": clean(company.siren),
    "sirene.name": clean(company.nom_raison_sociale) || clean(company.nom_complet),
    "sirene.acronym": clean(company.sigle),
    "sirene.vatNumber": clean(vatNumbers[0]),
    "sirene.legalFormCode": clean(company.nature_juridique),
    "sirene.activityCode": clean(company.activite_principale),
    "sirene.companyCategory": clean(company.categorie_entreprise),
    "sirene.employeeRange": EMPLOYEE_RANGES[company.tranche_effectif_salarie] || null,
    "sirene.creationDate": dateOnly(company.date_creation),
    "sirene.closureDate": dateOnly(company.date_fermeture),
    "sirene.status": state === "A" ? "Active" : state === "C" ? "Ceased" : null,
    "sirene.headOfficeSiret": clean(headOffice.siret),
    "sirene.headOfficeAddress": clean(headOffice.adresse),
    "sirene.postalCode": clean(headOffice.code_postal),
    "sirene.city": clean(headOffice.libelle_commune),
    "sirene.openEstablishments":
      typeof company.nombre_etablissements_ouverts === "number" ? company.nombre_etablissements_ouverts : null,
  };

  // Leave out values the register 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;
}

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

  const cacheKey = `sirene:${siren}`;
  const cached = CACHE_MILLISECONDS > 0 ? cache.get(cacheKey) : null;
  let data = cached ? parseJson(String(cached)) : null;

  if (!data) {
    const company = lookUp(siren);
    if (!company) {
      return [];
    }
    data = toData(company);
    if (CACHE_MILLISECONDS > 0) {
      cache.set(cacheKey, JSON.stringify(data), CACHE_MILLISECONDS);
    }
  }

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

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

Up: [REST API enricher samples](http://0.0.0.0:4000/govern/rest-api-enricher-samples.md)
