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

# Consultando pela Raiz do CNPJ

Na API comercial você também pode fazer uma consulta utilizando a raiz do CNPJ, que são os 8 primeiros dígitos do CNPJ e que, nesse caso, irá retornar todos os CNPJs da empresa em questão. Nesse endpoint, você deve enviar o header `x_api_token` com o token que lhe foi enviado via e-mail.

Você também pode passar o token como um parâmetro na URL, exemplo:

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

**Método:** `GET`

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

### Exemplo de Requisição

{% openapi src="/files/yN7Vsxppv1Cc8yHrLKTq" path="/cnpj-raiz/{cnpj-raiz}" method="get" %}
[doc-cnpjws-atualizado-2025-10-24.yaml](https://4279644561-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8bYi4hNysyQhSkVjnsqf%2Fuploads%2FTHbmxFLYiXOBxhtDiWO9%2Fdoc-cnpjws-atualizado-2025-10-24.yaml?alt=media\&token=dc4a718e-5f7b-4b71-962b-03a50464cdfe)
{% 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/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.
