# Trading Economics API Authentication

> Details of API Authentication

Source: https://docs.tradingeconomics.com/get_started/authentication/

To access the API, [subscribe to a plan](https://tradingeconomics.com/analytics/pricing.aspx) and get your API key at [developer.tradingeconomics.com](https://developer.tradingeconomics.com/). You can pass the key as a **c** or **client** URL parameter, or using a more secure way, passing an **Authorization** HTTP header:

## Authentication

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

The response data format can be configured by appending the **&f=** parameter to the URL request (supported formats: JSON or CSV)

```python
url = f'https://api.tradingeconomics.com/country/mexico?c={your_api_key}&f=csv'
```

You can use **request headers** to pass the API key:
```python
import requests

response = requests.get('https://api.tradingeconomics.com/country/mexico', headers = {'Authorization': 'your_api_key'})
print(response.json())
```

**JS**
```js
const axios = require('axios');
(async () => {    
    const your_api_key = 'your_api_key'
    const response = await axios.get(`https://api.tradingeconomics.com/country/mexico?c=${your_api_key}`)
    console.log(response.data)
})()
```

The response data format can be configured by appending the **&f=** parameter to the URL request (supported formats: JSON or CSV)

```javascript
const response = await axios.get(`https://api.tradingeconomics.com/country/mexico?c=${your_api_key}&f=csv`)
```

You can use **request headers** to pass the API key:
```javascript
(async () => {
  const url = 'https://api.tradingeconomics.com/country/mexico';
  const headers = { 'Authorization': 'your_api_key' };

  try {
    const response = await fetch(url, { method: 'GET', headers });
    const data = await response.text();
    console.log(data);
  } catch (error) {
    console.error(error);
  }
})();
```

**C#**
To use Trading Economics API with any server based language, copy and paste an endpoint and change its parameters to what you like.

By default, Server based languages show data as string: 

```c#
using (var httpClient = new HttpClient())
{
    using (var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.tradingeconomics.com/country/mexico?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 (supported formats: JSON or CSV)

```c#
new HttpRequestMessage(new HttpMethod("GET"), "https://api.tradingeconomics.com/country/mexico?c=your_api_key&f=csv")
```

