CNPJ coordinates and maps in the API
Get the latitude and longitude of a CNPJ's address via the API, with the point's precision, and render map, satellite and street view images.
Tip: Concepts on this page: Address coordinates and imagery and Resources with their own rules.
The API turns a CNPJ’s registered address into three forms of location: the geographic coordinates, a map image and a street-level image. The coordinates are an optional resource of Lookup CNPJ, requested in expand, and the images have their own operations. All of them are generated from the registered address by a third-party service, described in Data sources, and require an API key.
The location is always that of the CNPJ looked up, based on the establishment’s address in the Receita Federal registry, and the images carry no coordinates. Where the coordinates come from, their precision and the case of an address that cannot be located are in Address coordinates and imagery.
Request
| Operation | Method and path | Response |
|---|---|---|
| Lookup CNPJ | GET / | Registration JSON, with address. |
| Render CNPJ map | GET / | PNG image |
| Render CNPJ street view | GET / | JPEG image |
In all three operations, taxId is the CNPJ with 14 characters, no punctuation, uppercase letters in an alphanumeric CNPJ and valid check digits.
Lookup CNPJ
Add address. to expand on Lookup CNPJ. The value can be combined with the other optional resources, as in expand=address., described in CNPJ lookup.
| Parameter | Location | Use |
|---|---|---|
taxId | Path | Establishment CNPJ |
expand | Query | Include address. to receive the coordinates |
GET /v2/establishments/37335118000180?expand=address.coordinates HTTP/1.1
Host: api.cnpja.com
Authorization: YOUR_API_KEY maxAge still applies to the registration data, but not to the coordinates, as explained in Sources and updates. There is no address. parameter.
Render CNPJ map
Render CNPJ map returns a map centered on the registered address, with a marker at that point.
| Parameter | Location | Use |
|---|---|---|
taxId | Path | Establishment CNPJ |
type | Query | Map style, described in Image options. Defaults to ROADMAP |
curl "https://api.cnpja.com/v2/establishments/37335118000180/map" \
-H "Authorization: YOUR_API_KEY" \
-o map.png Render CNPJ street view
Render CNPJ street view returns an image of the registered address seen from street level. The operation has no query parameters: only the CNPJ in the path.
| Parameter | Location | Use |
|---|---|---|
taxId | Path | Establishment CNPJ |
curl "https://api.cnpja.com/v2/establishments/37335118000180/street-view" \
-H "Authorization: YOUR_API_KEY" \
-o street-view.jpg Response fields
With expand=address., the coordinates come inside address. Response trimmed to the address:
{
"taxId": "37335118000180",
"address": {
"street": "Avenida Brigadeiro Faria Lima",
"number": "2369",
"district": "Jardim Paulistano",
"city": "São Paulo",
"state": "SP",
"coordinates": {
"latitude": -23.5774497,
"longitude": -46.6864131,
"precision": "ADDRESS"
}
}
} | Field | Content |
|---|---|
address. | Coordinates of the registered address. Absent when address. is not in expand |
address. | Latitude in decimal degrees, negative south of the Equator, or null when the address cannot be located |
address. | Longitude in decimal degrees, negative west of the Greenwich meridian, or null when the address cannot be located |
address. | Point the coordinates stand for: ADDRESS (the address itself), DISTRICT (the district) or MUNICIPALITY (the municipality seat), described in Precision, or null when the address cannot be located |
- Handle the
nullcase before placing the establishment on a map or calculating distances. - Check that
precisionisADDRESSbefore treating the point as the establishment’s location or rendering the map and the street view, which atDISTRICTorMUNICIPALITYwould not show the establishment. - The other
addressfields follow the format described in CNPJ lookup.
Images
A 200 response from the image operations carries the file itself, not JSON. Size and framing are in Fixed characteristics.
| Operation | Content-Type | Format |
|---|---|---|
| Render CNPJ map | image/ | PNG image of 640 × 640 pixels |
| Render CNPJ street view | image/ | JPEG image of 640 × 640 pixels |
Errors come as JSON, in the same format as every other operation. Check the status before using the file:
const response = await fetch('https://api.cnpja.com/v2/establishments/37335118000180/map', {
headers: { Authorization: process.env.CNPJA_API_KEY },
});
if (response.status === 200) {
const image = Buffer.from(await response.arrayBuffer());
// use the image within the image usage rules
} else {
const error = await response.json();
} Render the images on your server, where the key is kept, and never in the browser, as explained in Authentication. If you store the file to show it again, respect the storage limits in the Google Maps Platform terms, as the Terms of Use state, and the image usage rules.
The images are rendered from the registered address, sent as text to the maps service, without checking the coordinates or their precision. That is why the image operations do not answer 404 for a missing location or street view:
- When the service returns an image, the response is
200, even when it does not show the establishment: the map is centered where the service places the address, and a place with no street imagery gets a gray image, with no photo, in place of the street view. That image is charged like any other. - To avoid rendering images of a point that is not the establishment’s, check first that
address.iscoordinates. precision ADDRESS. Even at that precision, the street view can come back gray. - A failure of the maps service ends in a
500, which is not charged, as the metering rules set. Retry the request later.
Image options
Map type
The type parameter of Render CNPJ map picks the style of the image:
type | Image |
|---|---|
ROADMAP | Street and road map (default) |
TERRAIN | Map with terrain elevation |
SATELLITE | Satellite imagery |
HYBRID | Satellite imagery with streets and roads overlaid |
GET /v2/establishments/37335118000180/map?type=SATELLITE HTTP/1.1
Host: api.cnpja.com
Authorization: YOUR_API_KEY A value outside this list is rejected with 400 REQUEST_.
Fixed characteristics
The other characteristics of the images cannot be configured:
| Characteristic | Map | Street view |
|---|---|---|
| Size | 640 × 640 pixels | 640 × 640 pixels |
| Framing | Centered on the address, with a marker, at zoom level 17 | 90° horizontal field of view, with no choice of heading or pitch |
| Extra parameters | Rejected with 400 REQUEST_, such as zoom | Ignored |
To show a larger area around the address, use the coordinates on your own map, where you control the zoom.
Sources and updates
The coordinates are calculated once per address and shared by the establishments with the same registered address, and the images are generated on every request, as explained in Address coordinates and imagery. In the API, this works as follows:
- Coordinates do not follow
maxAge. A smallermaxAgecan refresh the address, but it does not recompute the coordinates or the precision of an address that did not change. - Address not located. When the address cannot be located,
latitude,longitudeandprecisionarenull, and the computation is repeated on every request that includesaddress.. Coordinates withcoordinates DISTRICTorMUNICIPALITYprecision already count as located and are not recomputed on every request. - Images use the cached address. Map and street view accept no
maxAgeand start from the address already stored, which Lookup CNPJ updates. To render the image of a recently changed address, first look up the CNPJ with a shortmaxAge. - CNPJ not in cache. A CNPJ that is not in cached data yet is queried live at the Receita Federal before the image is generated.
The general rules for cache and maxAge are in Max age and partial success.
Partial success
Computing the coordinates is a live query, with up to 30 seconds. If it fails or exceeds that time, Lookup CNPJ responds with 206, with latitude, longitude and precision set to null, and delivers the other resources normally. The coordinates are not charged in that case; repeat the request later. See Max age and partial success.
The image operations never return 206: the image is generated in full or the request fails.
Billing
address. is charged as a Lookup CNPJ resource, cached when the coordinates are already computed and live when they are computed during the request, and each image generated is charged live, with no reuse and with no separate charge for the Receita Federal query of a CNPJ not in cache. The consumption of each case is in the Metering Rules, under CNPJ lookup and Generate map and street view.
Important: request
address.only when you will use the coordinates. While the address cannot be located, every request with this value repeats the computation and is charged as a live query, as explained in Address not located.coordinates
Frequent errors
| Status | Code | Cause | Action |
|---|---|---|---|
400 | REQUEST_ | CNPJ not in the 14-character format or with invalid check digits | Send the CNPJ with no punctuation and with uppercase letters |
400 | REQUEST_ | On Render CNPJ map, type outside the accepted values or an unrecognized parameter, such as zoom | Send a value from Map type and check the spelling of the parameters, since errors does not name the rejected one |
401 | API_ | Map or street view without an API key, or Lookup CNPJ without a key and with expand | Send the API key in Authorization, as explained in First request |
402 | CACHED_, LIVE_ or OVERAGE_ | The organization’s quota or overage budget is used up. What each code means is in Error codes | Follow one of the ways out in Quota used up |
404 | ESTABLISHMENT_ | The CNPJ is not in the Receita Federal registry | Check the CNPJ. Do not repeat the request right away, since each 404 is charged as a live query |
The other errors and the retry rules are in Limits and errors.
Use cases
- Customer and supplier map: place your portfolio on your own map with the coordinates of each CNPJ and identify concentrations by region.
- Logistics and service areas: calculate the distance between the establishment and a distribution center to set shipping, lead time or the responsible representative.
- Sales visits: find the establishments in a region with CNPJ search, look up each CNPJ with
expand=address.and plan the visit routes from the coordinates.coordinates - Support for registration checks: use the street view, or the map with
SATELLITE, to check whether the stated address matches a property consistent with the activity, as part of onboarding a new customer. - Customer record: show the map or the street view on the customer record in your system, within the image usage rules.
In the app
On a CNPJ’s record, the Geolocation section shows the coordinates and their Precision and renders the aerial map and the street view only when you click Load, and only at Address precision, as explained in Map, street view and coordinates. To recompute the coordinates, use the section’s refresh button; Update all and automatic updates only calculate them when the record has none yet. In exports, the coordinates are the Address coordinates resource, described in Export to a spreadsheet.
Notes
- The coordinates are only on Lookup CNPJ. Lookup company and Search CNPJ neither return nor filter by them, and the CEP operations do not return coordinates either.
- Map and street view do not accept public requests, and Lookup CNPJ without a key does not accept
expand, so none of the three forms of location is available without a key. See Public access. - The address of state registrations and of SUFRAMA comes from other registries and is not used for the coordinates or the images.
- All parameters are in Lookup CNPJ, Render CNPJ map and Render CNPJ street view.