CNPJ.ws
Blog

How to automate customer registration with a CNPJ lookup API

Eliminate manual data entry when registering companies by using a CNPJ lookup API to fill in legal name, address, economic activity and tax regime automatically.

How many times has your team typed a new customer's legal name, address, economic activity (CNAE) and state registration — field by field — copying from the Federal Revenue's CNPJ card? Besides being slow, this process is the main entry point for registration errors: a wrong digit in the CNPJ, an outdated address, a legal name abbreviated differently in each system.

The good news is that none of this has 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 on its own, with official and 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 companies — 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 someone fills in while looking at documents. The costs show up on three fronts:

  • Time: each registration consumes minutes of repetitive work, multiplied by every customer and supplier in the database.
  • Errors: manual typing creates discrepancies that spread to invoices, payment slips and contracts — plus rework to fix them.
  • Outdated data: the company changes its address or registration status, and the record in your system still holds the old information.

How a CNPJ lookup API works

A CNPJ lookup API exposes public data about 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, economic activities (CNAEs), ownership structure, state registrations and tax regime (Simples Nacional/MEI).

The automation flow has three steps:

1. The user provides only the CNPJ

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

2. The system queries the API

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

The response carries the complete company object. The CNPJ.ws public API allows up to 3 queries per minute — enough for testing and for 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, primary CNAE, tax regime. The user only reviews and confirms. What used to take minutes now takes seconds — and the data arrives exactly as it appears in the official database.

Real case: AI-driven customer registration in bitERP

One example of this flow running in production is bitERP, an ERP with artificial intelligence, developed in Brazil. In bitERP, the user can 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 record on screen and only asks for the final confirmation.

The combination is interesting because it joins two automations: the AI removes the navigation through menus and forms, and the CNPJ lookup API removes the searching and typing of the data. The result is a customer onboarding that gets resolved 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.

Best practices when integrating

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

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

Get started now

You can test the query right now, with no sign-up: just call https://publica.cnpj.ws/cnpj/{number} and see the JSON returned. To take the integration to production, check out the CNPJ.ws commercial API plans — and if you want to see the automated registration flow working inside an ERP, the bitERP example shows how far this automation can go.

On this page