> 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/en/api-reference/api-comercial/consultando-raiz-cnpj.md).

# Consulting by CNPJ Root

In the commercial API, you can also query using the CNPJ root, which are the first 8 digits of the CNPJ and, in this case, will return all CNPJs of the company in question. In this endpoint, you must send the `x_api_token` header with the token that was sent to you via email.

You can also pass the token as a parameter in the URL, example:

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

**Method:** `GET`

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

### Request Example

{% openapi src="/files/pX97Qdj2qn3xNQOZEdoV" path="/cnpj-raiz/{cnpj-raiz}" method="get" %}
[openapi-comercial.yaml](https://content.gitbook.com/content/543mjjjP3f2OCfQR723f/blobs/Fw4vf2BKurgpfEERuww1/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);
}
```

[Mais informações do pacote](https://www.npmjs.com/package/consultar-cnpj)

#### Paginação

Caso a empresa possua mais de 20 filiais a API irá dividir a resposta em páginas. Você pode verificar isso no JSON de retono da API, na propriedade "paginacao", que exibe a página atual, o total de páginas e o total de filiais:

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

Para buscar uma página específica basta informar o número da página na requisição:

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

#### Exemplo de Retorno

Abaixo um exemplo do JSON retornado ao se buscar pela raiz do 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/en/api-reference/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.
