Consulting by CNPJ Root
How to query all establishments of a company by the CNPJ root (first 8 digits) in the CNPJ.ws Commercial API.
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
Token de API (Bearer). Ex.: Authorization: Bearer <seu_token>
In: header
Path Parameters
^\d{8}$Query Parameters
Header Parameters
Response Body
application/json
application/json
application/json
curl -X GET "https://example.com/cnpj-raiz/string"{ "data": [ "string" ], "paginacao": { "limite": 0, "pagina": 0, "paginas": 0 }, "ordenacao": [ "string" ], "filtros_disponiveis": [ "string" ], "filtros_aplicados": { "nome_fantasia": "string", "pais_id": "string", "estado_id": "string", "cidade_id": "string", "atividade_principal_id": "string", "tipo": "string" }}{ "status": 0, "titulo": "string", "detalhes": "string", "validacao": [ "string" ], "statusCode": 0, "message": "string", "error": "string"}{ "status": 0, "titulo": "string", "detalhes": "string", "validacao": [ "string" ], "statusCode": 0, "message": "string", "error": "string"}yarn add consultar-cnpjconst 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);
}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:
{
"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:
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:
{
"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": {}
}