Trading Economics API Authentication
To access the API, subscribe to a plan and get your API key at 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
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)
url = f'https://api.tradingeconomics.com/country/mexico?c={your_api_key}&f=csv'
You can use request headers to pass the API key:
import requests
response = requests.get('https://api.tradingeconomics.com/country/mexico', headers = {'Authorization': 'your_api_key'})
print(response.json())
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)
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:
(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);
}
})();
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:
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)
new HttpRequestMessage(new HttpMethod("GET"), "https://api.tradingeconomics.com/country/mexico?c=your_api_key&f=csv")