cne.gob.mx APIwww.cne.gob.mx ↗
Query current gasoline and diesel prices for all Mexican gas stations by state and municipality via the CNE cne.gob.mx API. Covers Regular, Premium, and Diesel.
No input parameters required.
curl -X GET 'https://api.parse.bot/scraper/8412a138-d867-4a05-a6e1-019af32d5f4e/get_states' \ -H 'X-API-Key: $PARSE_API_KEY'
Get all 32 Mexican states (entidades federativas) with their IDs. Use these IDs to query municipalities and fuel prices.
No input parameters required.
{
"type": "object",
"fields": {
"total": "integer — number of states returned",
"states": "array of objects with entidad_federativa_id (zero-padded 2-digit string) and nombre (state name)"
},
"sample": {
"data": {
"total": 32,
"states": [
{
"nombre": "Aguascalientes",
"entidad_federativa_id": "01"
},
{
"nombre": "Ciudad de México",
"entidad_federativa_id": "09"
}
]
},
"status": "success"
}
}About the cne.gob.mx API
The CNE Mexico Fuel Prices API exposes 4 endpoints that return current Regular gasoline, Premium gasoline, and Diesel prices for gas stations across all 32 Mexican states. Starting with get_states to retrieve state IDs, you can drill down to municipality-level station data or pull all prices for an entire state in a single call using get_all_fuel_prices. Each station record includes address, product type, sub-product, and the active price.
Endpoints and Data Coverage
The API is organized as a two-level geographic hierarchy: states (entidades federativas) and municipalities. get_states returns all 32 Mexican states with their zero-padded two-digit IDs and names — these IDs are required inputs for every downstream query. get_municipalities accepts an entidad_id and returns a list of municipality objects, each with an entidad_federativa_id, a zero-padded three-digit municipio_id, and the municipality name.
Station-Level Fuel Prices
get_fuel_prices takes both entidad_id and municipio_id and returns all station-product entries for that municipality. Each entry in the stations array carries a station number (numero), direccion (street address), producto, sub_producto, and precio_vigente (the current numeric price). The total field tells you how many entries were returned. The three fuel products covered are Regular gasoline, Premium gasoline, and Diesel, so a single physical station typically produces three entries.
State-Wide Price Queries
get_all_fuel_prices accepts a required entidad_id and iterates across every municipality in that state, returning a unified stations array and a total_stations count. Because it aggregates across all municipalities, response time can range from 10 to 30 seconds for states with many municipalities. An errors array will appear in the response only when one or more municipality requests fail, letting you identify any gaps in coverage without silently discarding data.
- Build a fuel price comparison map for Mexican drivers, plotting
precio_vigentebydireccionfor all stations in a municipality. - Track daily or weekly price changes for Regular and Premium gasoline across a state using
get_all_fuel_priceswith scheduled calls. - Identify the cheapest diesel corridor along a freight route by querying
get_fuel_pricesfor municipalities along the path. - Feed a logistics cost calculator with live diesel prices from specific states to estimate transportation expenses.
- Monitor regulatory compliance by flagging stations whose
precio_vigentedeviates significantly from the state average. - Populate a mobile app's 'nearest cheap fuel' feature using station addresses and current prices from
get_fuel_prices. - Aggregate historical price data by state for economic research on fuel inflation in Mexico.
| Tier | Price | Credits/month | Rate limit |
|---|---|---|---|
| Free | $0/mo | 100 | 5 req/min |
| Hobby | $30/mo | 1,000 | 20 req/min |
| Developer | $100/mo | 5,000 | 250 req/min |
One credit = one API call regardless of which marketplace API you call. Exceeding the rate limit returns a 429 response. Authenticate with the X-API-Key header.
Does CNE (cne.gob.mx) have an official developer API?+
What does each entry in the `stations` array actually contain?+
stations represents one fuel product at one station. It includes numero (station identifier), direccion (address), producto (fuel category), sub_producto (fuel sub-type), precio_vigente (the active price as a number), and entidad_federativa_id as an integer. A single physical station will appear as multiple entries — one per fuel product carried.Does the API include geographic coordinates (latitude/longitude) for each station?+
direccion (a street address) but no latitude or longitude fields. You can fork this API on Parse and revise it to add a geocoding step that resolves addresses to coordinates.How fresh are the fuel prices returned by the API?+
Can I filter `get_fuel_prices` results by a specific fuel type, such as only Diesel?+
producto or sub_producto. The full set of station-product entries for the municipality is returned, and filtering by fuel type must be done client-side on the stations array. You can fork this API on Parse and revise it to expose a producto filter parameter.