> 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/blog/como-automatizar-o-cadastro-de-clientes-com-uma-api-de-consulta-cnpj.md).

# How to Automate Customer Registration with a CNPJ Lookup API

How many times has your team typed a new customer's legal name, address, CNAE code, and state registration — field by field — copying from the Brazilian Federal Revenue's CNPJ card? Besides being slow, this process is the main source of registration errors: one wrong digit in the CNPJ, an outdated address, a company name abbreviated differently in every system.

The good news: none of this needs to be manual. With a **CNPJ lookup API**, your system asks the user for a single piece of data — the CNPJ number — and fills in everything else automatically, with official, up-to-date information. In this post, we show how this flow works, how to implement it with the CNPJ.ws API, and how a Brazilian ERP uses exactly this approach in production.

### The problem with manual registration

Every system that serves businesses — ERP, CRM, billing platform, B2B e-commerce — needs to register legal entities. In the manual flow, that means a form with 10 to 20 fields that someone fills in by consulting documents. The costs show up on three fronts:

* **Time**: each registration consumes minutes of repetitive work, multiplied across every customer and supplier in your base.
* **Errors**: manual typing creates inconsistencies that propagate to invoices, billing, and contracts — plus the rework to fix them.
* **Stale data**: the company changes its address or registration status, and your system keeps the old information.

### How a CNPJ lookup API works

A CNPJ lookup API exposes the public data of Brazilian companies in a structured format (JSON), ready to be consumed by any application. With CNPJ.ws, a single HTTP request returns the legal name, trade name, registration status, legal nature, company size, full address, CNAE activity codes, ownership structure, state registrations, and tax regime (Simples Nacional/MEI).

The automation flow has three steps:

#### 1. The user enters only the CNPJ

In the registration form, the only required field becomes the CNPJ number. It's worth validating the check digits on the front end before querying, avoiding unnecessary calls.

#### 2. The system queries the API

```bash
curl https://publica.cnpj.ws/cnpj/00000000000191
```

The response brings the company's complete data object. The free public CNPJ.ws API allows up to 3 requests per minute — enough for testing and low volumes. For production use, the commercial API offers higher limits, additional data, and an SLA.

#### 3. The form fills itself

With the response in hand, the system populates every field: legal name, address, main CNAE, tax regime. The user just reviews and confirms. What used to take minutes now takes seconds — and the data arrives exactly as it appears in the official government registry.

### Real-world case: AI-powered customer registration in bitERP

One example of this flow running in production is [bitERP, an AI-powered ERP](https://www.biterp.ai) built in Brazil. In bitERP, the user can simply ask in the chat something like *"register the customer with CNPJ 00.000.000/0001-00"* — and the AI agent queries the CNPJ.ws API, fills in the complete customer record on screen, and asks only for final confirmation.

The combination is powerful because it stacks two automations: the AI eliminates navigating through menus and forms, and the CNPJ lookup API eliminates searching for and typing the data. The result is customer onboarding that resolves in a single sentence, with official Federal Revenue data — no typos, no incomplete records.

The same pattern applies to suppliers, carriers, and any other legal entity in the system.

### Integration best practices

To get the most out of the integration, a few recommendations:

* **Validate the CNPJ before querying** — check-digit validation is a local calculation; don't waste a request on an invalid number.
* **Handle rate limits** — implement retry with backoff for 429 errors, and consider the commercial API for volume.
* **Store the lookup date** — registration data changes; knowing when a record was last synced lets you schedule periodic updates.
* **Alert on registration status** — if the company shows as closed, suspended, or irregular, flag it before completing the registration. This prevents issuing invoices to an irregular CNPJ.
* **Let the user review** — automation fills, a human confirms. Especially fields the customer may want to override, such as the trade name.

### Get started now

You can test a lookup right now, no sign-up required: just call `https://publica.cnpj.ws/cnpj/{number}` and see the JSON response. To take your integration to production, check out the [CNPJ.ws commercial API plans](https://www.cnpj.ws) — and if you want to see automated registration working inside an ERP, the bitERP example shows how far this automation can go.


---

# 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/blog/como-automatizar-o-cadastro-de-clientes-com-uma-api-de-consulta-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.
