Skip to content
CNPJ coordinates and maps in the API
API · Features

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

OperationMethod and pathResponse
Lookup CNPJGET /v2/establishments/{taxId}?expand=address.coordinatesRegistration JSON, with address.coordinates
Render CNPJ mapGET /v2/establishments/{taxId}/mapPNG image
Render CNPJ street viewGET /v2/establishments/{taxId}/street-viewJPEG 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.coordinates to expand on Lookup CNPJ. The value can be combined with the other optional resources, as in expand=address.coordinates,company.taxRegime, described in CNPJ lookup.

ParameterLocationUse
taxIdPathEstablishment CNPJ
expandQueryInclude address.coordinates 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.coordinates.maxAge parameter.

Render CNPJ map

Render CNPJ map returns a map centered on the registered address, with a marker at that point.

ParameterLocationUse
taxIdPathEstablishment CNPJ
typeQueryMap 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.

ParameterLocationUse
taxIdPathEstablishment 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.coordinates, 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"
    }
  }
}
FieldContent
address.coordinatesCoordinates of the registered address. Absent when address.coordinates is not in expand
address.coordinates.latitudeLatitude in decimal degrees, negative south of the Equator, or null when the address cannot be located
address.coordinates.longitudeLongitude in decimal degrees, negative west of the Greenwich meridian, or null when the address cannot be located
address.coordinates.precisionPoint 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 null case before placing the establishment on a map or calculating distances.
  • Check that precision is ADDRESS before treating the point as the establishment’s location or rendering the map and the street view, which at DISTRICT or MUNICIPALITY would not show the establishment.
  • The other address fields 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.

OperationContent-TypeFormat
Render CNPJ mapimage/pngPNG image of 640 × 640 pixels
Render CNPJ street viewimage/jpegJPEG 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.coordinates.precision is 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:

typeImage
ROADMAPStreet and road map (default)
TERRAINMap with terrain elevation
SATELLITESatellite imagery
HYBRIDSatellite 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_VALIDATION_FAILED.

Fixed characteristics

The other characteristics of the images cannot be configured:

CharacteristicMapStreet view
Size640 × 640 pixels640 × 640 pixels
FramingCentered on the address, with a marker, at zoom level 1790° horizontal field of view, with no choice of heading or pitch
Extra parametersRejected with 400 REQUEST_VALIDATION_FAILED, such as zoomIgnored

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 smaller maxAge can 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, longitude and precision are null, and the computation is repeated on every request that includes address.coordinates. Coordinates with DISTRICT or MUNICIPALITY precision already count as located and are not recomputed on every request.
  • Images use the cached address. Map and street view accept no maxAge and 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 short maxAge.
  • 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.coordinates 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.coordinates 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.

Frequent errors

StatusCodeCauseAction
400REQUEST_VALIDATION_FAILEDCNPJ not in the 14-character format or with invalid check digitsSend the CNPJ with no punctuation and with uppercase letters
400REQUEST_VALIDATION_FAILEDOn Render CNPJ map, type outside the accepted values or an unrecognized parameter, such as zoomSend a value from Map type and check the spelling of the parameters, since errors does not name the rejected one
401API_KEY_MISSINGMap or street view without an API key, or Lookup CNPJ without a key and with expandSend the API key in Authorization, as explained in First request
402CACHED_QUERY_QUOTA_EXCEEDED, LIVE_QUERY_QUOTA_EXCEEDED or OVERAGE_BUDGET_EXCEEDEDThe organization’s quota or overage budget is used up. What each code means is in Error codesFollow one of the ways out in Quota used up
404ESTABLISHMENT_NOT_FOUNDThe CNPJ is not in the Receita Federal registryCheck 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.coordinates and plan the visit routes from the 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

Informational content that may change without notice. It is not tax, accounting or legal advice, and CNPJá's terms and policies prevail over this page.