This project is a REST API that fetches the realtime prices from the government's public API, and offers them with more filtering options.
Data source: Spanish government public API | Endpoints list
The API fetches the historic data between the last date on the database and the current date when the API is started, and every day at 01:00 AM, however, the database must have some preloaded data in order to fetch that remaining data. I have created a tool to fetch the historic data from the public API and then import it to the persistent database. Follow the instructions on that repository to fetch the data and import to the database.
This endpoint returns all the information about the service stations. This endpoint has different operation modes:
- Normal operation: It returns the list of service stations as they come from the government API. It offers the parameters
limit
andoffset
. Withlimit
you define how many items you want to get, and withoffset
you choose the index of the first item you want to get. For example, if you want to retrieve items from 100 to 199 you will have to setlimit
to 200 andoffset
to 100. The API won't give you more than 200 items for each batch. - Stations in a municipality: Use the parameter
municipalityId
to get the stations that correspond to that municipality. If you use themunicipalityId
parameter, you will get all the stations in that municipality, ignoring thelimit
andoffset
parameters. - Coordinates: It will return the stations that are in a radius from the given coordinates. With the
coordinates
parameter you define the center of the circle (format example:coordinates=40.416826,-3.703675
), and with thedistance
parameter you define the radius of the circle. The API will return all the service stations that are inside that circle. The distance has to be inputted in Km and cannot be greater than 50. - Defined list of service stations: You can use the parameter
id
, and pass one or multiple ids of service stations to get the information of them. Example:id=1234&id=2345&id=3456
.
Required parameters:
- id: The station id
- startDate: The date where you want to start getting results, in format
yyyy-mm-dd
- endDate: The date where you want to stop getting results, in format
yyyy-mm-dd
The maximum difference between startDate
and endDate
cannot be greater than 1 year, and startDate
must be an earlier date than endDate
.
That will return a list of prices sorted ASC including also the station id and the date of that values.
Optional parameters:
- includeCurrentPrices: This is a boolean flag to add the current prices to the result.
Returns the complete list of municipalities in Spain.
If you like the project and you want to contribute with the development, you can become a sponsor on GitHub, or you can donate using PayPal.