> For the complete documentation index, see [llms.txt](https://docs.cnpj.ws/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cnpj.ws/es/referencia-de-api/api-comercial/consultando-raiz-cnpj.md).

# Consultando por la Raíz del CNPJ

En la API comercial también puedes hacer una consulta utilizando la raíz del CNPJ, que son los 8 primeros dígitos del CNPJ y que, en este caso, devolverá todos los CNPJs de la empresa en cuestión. En este endpoint, debes enviar el header `x_api_token` con el token que te fue enviado por correo electrónico.

También puedes pasar el token como un parámetro en la URL, ejemplo:

`https://comercial.cnpj.ws/cnpj-raiz/27865757?token=SEU_TOKEN`

**Método:** `GET`

**Endpoint:** `https://comercial.cnpj.ws/cnpj-raiz/RAIZ_DO_CNPJ`

### Ejemplo de Solicitud

{% openapi src="/files/pX97Qdj2qn3xNQOZEdoV" path="/cnpj-raiz/{cnpj-raiz}" method="get" %}
[openapi-comercial.yaml](https://content.gitbook.com/content/ZYWCe6C3PGIrqh1fMqTq/blobs/SZMKPqHjWKTxdfdW0HvX/openapi-comercial.yaml)
{% endopenapi %}

```shell
yarn add consultar-cnpj
```

```js
const consultarCNPJ = require("consultar-cnpj");

async function getRaiz() {
  const token = "INFORME O SEU TOKEN DE ACESSO";

  const data = await consultarCNPJ.raiz("27865757", token);
  console.log(data);
}
```

[Más información del paquete](https://www.npmjs.com/package/consultar-cnpj)

#### Paginación

En caso de que la empresa tenga más de 20 filiales, la API dividirá la respuesta en páginas. Puedes verificar esto en el JSON de retorno de la API, en la propiedad "paginacion", que muestra la página actual, el total de páginas y el total de filiales:

```json
{
  "paginacao": {
    "limite": 20,
    "pagina": 1,
    "paginas": 5,
    "total": 87
  }
}
```

Para buscar una página específica basta con informar el número de la página en la solicitud:

```shell
curl -X GET https://comercial.cnpj.ws/cnpj-raiz/27865757?page=2 -H "x_api_token: SEU_TOKEN"
```

#### Ejemplo de Retorno

A continuación, un ejemplo del JSON retornado al buscar por la raíz del CNPJ **27865757**:

```json
{
  "data": [
    "27865757002148",
    "27865757002229",
    "27865757002300",
    "27865757002490",
    "27865757002571",
    "27865757002652",
    "27865757002733",
    "27865757002814",
    "27865757002903",
    "27865757003039",
    "27865757003110",
    "27865757003209",
    "27865757003381",
    "27865757003462",
    "27865757003543",
    "27865757003624",
    "27865757003705",
    "27865757003896",
    "27865757003977",
    "27865757004000"
  ],
  "paginacao": {
    "limite": 20,
    "pagina": 2,
    "paginas": 5,
    "total": 87
  },
  "ordenacao": [],
  "filtros_disponiveis": ["nome_fantasia", "pais_id", "estado_id", "cidade_id"],
  "filtros_aplicados": {}
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.cnpj.ws/es/referencia-de-api/api-comercial/consultando-raiz-cnpj.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
