Retrieve an Access Token
Please refer to the following examples in order to send a POST for retrieving an Access
Token.
JavaScript - Fetch
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
var urlencoded = new URLSearchParams();
urlencoded.append("grant_type", "client_credentials");
urlencoded.append("client_id", "your_API_Key");
urlencoded.append("client_secret", "your_API_Secret");
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: urlencoded,
redirect: 'follow'
};
fetch("https://api.terna.it/public-api/access-token", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
Python - Requests
import requests
url = "https://api.terna.it/public-api/access-token"
payload = 'grant_type=client_credentials&client_id=your_API_Key&client_secret=your_API_Secret'
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Java - OkHttp
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "grant_type=client_credentials&client_id=your_API_Key&client_secret=your_API_Secret");
Request request = new Request.Builder()
.url("https://api.terna.it/public-api/access-token")
.method("POST", body)
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
Response response = client.newCall(request).execute();
cURL
curl --location 'https://api.terna.it/public-api/access-token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=your_API_Key' \
--data-urlencode 'client_secret=your_API_Secret'
Calling our APIs
JavaScript - Fetch
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer n3fujtnubkgx48rhvcf7yxz7");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://api.terna.it/transparency/v1.0/gettotalload?dateFrom=10/05/2022&dateTo=11/05/2022", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
Python - Requests
import requests
url = "https://api.terna.it/transparency/v1.0/gettotalload?dateFrom=10/05/2022&dateTo=11/05/2022"
payload = {}
headers = {
'Authorization': 'Bearer n3fujtnubkgx48rhvcf7yxz7'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
Java - OkHttp
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
.url("https://api.terna.it/transparency/v1.0/gettotalload?dateFrom=10/05/2022&dateTo=11/05/2022")
.method("GET", body)
.addHeader("Authorization", "Bearer n3fujtnubkgx48rhvcf7yxz7")
.build();
Response response = client.newCall(request).execute();
cURL
curl --location 'https://api.terna.it/transparency/v1.0/gettotalload?dateFrom=10%2F05%2F2022&dateTo=11%2F05%2F2022' \
--header 'Authorization: Bearer n3fujtnubkgx48rhvcf7yxz7'