# Eurostat Historical Data

> Use the following API endpoints to obtain Eurostat historical data.

Source: https://docs.tradingeconomics.com/eurostat/historical/

The historical endpoint contains a time series with an indicator identifier, the reference date, the last update date and the observed value. It allows one to check the evolution of key indicators over time.

## By ID

**PYTHON**
*Using Requests:*
```python
import requests
your_api_key = 'your_api_key'
url = f'https://api.tradingeconomics.com/eurostat/historical/24804?c={your_api_key}'
data = requests.get(url).json()
print(data)
```

*Or using our package:*
```python
import tradingeconomics as te
te.login('your_api_key')
te.getHistoricalEurostat(ID = '24804')
```

**JS**
*Using Requests:*
```js
const axios = require('axios');
(async () => {
    const your_api_key = 'your_api_key'
    const response = await axios.get(`https://api.tradingeconomics.com/eurostat/historical/24804?c=${your_api_key}`)
    console.log(response.data)
})()
```
*Or using our package:*
```javascript
const te = require('tradingeconomics');
te.login('your_api_key');
data = te.getEurostatHistorical(id = '24804').then(function(data){
  console.log(data)       
});
```

**C#**
*Using Requests:*
```c#
using (var httpClient = new HttpClient())
{
    using (var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.tradingeconomics.com/eurostat/historical/24804?c=your_api_key"))
    {
        request.Headers.TryAddWithoutValidation("Upgrade-Insecure-Requests", "1");
        var response = await httpClient.SendAsync(request);
        if (response.IsSuccessStatusCode)
        {
            var content = await response.Content.ReadAsStringAsync(); 
            Console.WriteLine(content);
        }
    }
}
```

The response data format can be configured by appending the **&f=** parameter to the URL request.

**JSON**

```text
https://api.tradingeconomics.com/eurostat/historical/{id}?c={your_api_key}&f=json
```

```json
[
  {
    "ID": 24804,
    "Date": "2020-12-31T00:00:00",
    "Value": 2.4,
    "LastUpdate": "2021-04-20T23:16:00"
  },
  {
    "ID": 24804,
    "Date": "2019-12-31T00:00:00",
    "Value": 1.8,
    "LastUpdate": "2020-07-02T17:46:00"
  },
  {
    "ID": 24804,
    "Date": "2018-12-31T00:00:00",
    "Value": 2.1,
    "LastUpdate": "2020-07-02T17:46:00"
  }
]
```

**CSV**

```text
https://api.tradingeconomics.com/eurostat/historical/{id}?c={your_api_key}&f=csv
```

```bash
ID,Date,Value,LastUpdate
24804,12/31/2020 12:00:00 AM,2.4000,4/20/2021 11:16:00 PM
24804,12/31/2019 12:00:00 AM,1.8000,7/2/2020 5:46:00 PM
24804,12/31/2018 12:00:00 AM,2.1000,7/2/2020 5:46:00 PM
```

**HTML**

```text
https://api.tradingeconomics.com/eurostat/historical/{id}?c={your_api_key}
```

| ID | Date | Value | LastUpdate |
|-------|-------|-------|-------|
| 24804 | 12/31/2020 12:00:00 AM | 2.4000 | 4/20/2021 11:16:00 PM |
| 24804 | 12/31/2019 12:00:00 AM | 1.8000 | 7/2/2020 5:46:00 PM |
| 24804 | 12/31/2018 12:00:00 AM | 2.1000 | 7/2/2020 5:46:00 PM |

## By ID and date

**PYTHON**
*Using Requests:*
```python
import requests
your_api_key = 'your_api_key'
url = f'https://api.tradingeconomics.com/eurostat/historical/24804?d1=2015-01-01&c={your_api_key}'
data = requests.get(url).json()
print(data)
```

*Or using our package:*
```python
te.getHistoricalEurostat(ID = '24804', initDate = '2015-01-01')
```

*With end date:*
```python
te.getHistoricalEurostat(ID = '24804', initDate = '2016-01-01',
 endDate = '2020-01-01')
```

**JS**
*Using Requests:*
```js
const axios = require('axios');
(async () => {
    const your_api_key = 'your_api_key'
    const response = await axios.get(`https://api.tradingeconomics.com/eurostat/historical/24804?d1=2015-01-01&c=${your_api_key}`)
    console.log(response.data)
})()
```
*Or using our package:*
```javascript
data = te.getEurostatHistorical(id = '24804', start_date = '2016-01-01').then(function(data){
  console.log(data)       
});
```

*With end date:*
```javascript
data = te.getEurostatHistorical(id = '24804', start_date = '2016-01-01',
 end_date = '2020-01-01').then(function(data){
    console.log(data)     
});
```

**C#**
*Using Requests:*
```c#
using (var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.tradingeconomics.com/eurostat/historical/24804?d1=2015-01-01&c=your_api_key"))
```

**JSON**

```text
https://api.tradingeconomics.com/eurostat/historical/{id}?c={your_api_key}&d1={yyyy-mm-dd}&f=json
```

```json
[
  {
    "ID": 24804,
    "Date": "2020-12-31T00:00:00",
    "Value": 2.4,
    "LastUpdate": "2021-04-20T23:16:00"
  },
  {
    "ID": 24804,
    "Date": "2019-12-31T00:00:00",
    "Value": 1.8,
    "LastUpdate": "2020-07-02T17:46:00"
  },
  {
    "ID": 24804,
    "Date": "2018-12-31T00:00:00",
    "Value": 2.1,
    "LastUpdate": "2020-07-02T17:46:00"
  }
]
```

**CSV**

```text
https://api.tradingeconomics.com/eurostat/historical/{id}?c={your_api_key}&d1={yyyy-mm-dd}&f=csv
```

```bash
ID,Date,Value,LastUpdate
24804,12/31/2020 12:00:00 AM,2.4000,4/20/2021 11:16:00 PM
24804,12/31/2019 12:00:00 AM,1.8000,7/2/2020 5:46:00 PM
24804,12/31/2018 12:00:00 AM,2.1000,7/2/2020 5:46:00 PM
```

**HTML**

```text
https://api.tradingeconomics.com/eurostat/historical/{id}?c={your_api_key}&d1={yyyy-mm-dd}
```

| ID | Date | Value | LastUpdate |
|-------|-------|-------|-------|
| 24804 | 12/31/2020 12:00:00 AM | 2.4000 | 4/20/2021 11:16:00 PM |
| 24804 | 12/31/2019 12:00:00 AM | 1.8000 | 7/2/2020 5:46:00 PM |
| 24804 | 12/31/2018 12:00:00 AM | 2.1000 | 7/2/2020 5:46:00 PM |

## Response fields

| Field      | Type   | Description                                | Example               |
| -----------|--------|--------------------------------------------|-----------------------|
| ID         | number | Trading Economics unique identifier             | 24804               |
| Date       | string | Release date and time in UTC                     | "2020-12-31T00:00:00" |
| Value      | number | Reported value of the indicator                  | 2.4000              |
| LastUpdate | string | Timestamp when the data was last inserted or updated | "2021-04-20T23:16:00" |

