Hi
I am stiil working onagsi.gie.eu
I am trying to get some 2 apis with promise
and I get : [object Response],[object Response]
How can I get to data of array of two API?
let apiKey = "709a7d013e4fda8f3e21166c33a1a691";
let urls = ['https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001160J/AT',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/25X-OMVGASSTORA5/AT'];
let requests = urls.map(url => fetch(url, {
method: "GET",
headers: {
"x-key": apiKey
}}));
Promise.all(requests)
.then(response => alert(response));
You can’t use alert
, it will turn the array into a string and give you [object, Object]
.
let apiKey = "709a7d013e4fda8f3e21166c33a1a691";
let urls = [
"https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001160J/AT",
"https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/25X-OMVGASSTORA5/AT"
];
let requests = urls.map((url) =>
fetch(url, {
method: "GET",
headers: {
"x-key": apiKey
}
}).then((res) => res.json())
);
Promise.all(requests).then((response) => console.log(response));
1 Like
Dear all,
-
agsi web gives api to sinlge gas chamber operator, there are few operators in some countries. I have to get sum of all operators. For Example in Germany there are 25 - SSO (storage system operators). I have api for each of them.
-
I managed to get array of sum what I wanted, but it takes 20 seconds for Germany (largest)
-
What is the best way to get and use this data in chart, I am storing data localy. (maybe save as CSV once a day and with D3 or input data as variables in js file with pyton?
I am using it for learning purposes and now I am not eanough skilled to use server side.
let apiKey = "709a7d013e4fda8f3e21166c33a1a691";
let urls = [
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001160J/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/37X0000000000151/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/37X0000000000224/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001125L/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X0000000010849/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001368W/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X0000000011756/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001090E/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X0000000013805/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001262B/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001140P/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/37X000000000042Z/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X0000000011748/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/11XNERGIE------1/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/37X0000000000119/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/25X-OMVGASSTORA5/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/11XSWHANNOVERAG3/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001072G/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/11XSWB-BREMEN--I/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/37X000000000051Y/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001307F/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001310Q/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001127H/DE',
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001138C/DE',
];
let requests = urls.map((url) =>
fetch(url, {
method: "GET",
headers: {
"x-key": apiKey
}
}).then((res) => res.json())
);
Promise.all(requests).then((response) => arr_api_agsi(response));
function arr_api_agsi(response) {
var arr_api=[];
var l=[];
var i;
var j;
var jj;
var gas_date;
var response_length=response.length
for (i = 0; i < response_length; i++) {
arr_api.push(response[i]);
l.push(response[i].length);
}
var gas_vol=0;
var arr_max_index=0;
l.map((u)=>u.length>l[arr_max_index].length ? arr_max_index=l.indexOf(u.length):x=1);
var gas_storage=[];
var gas_storage_temp=[];
var len_single_arr;
var len_max_arr=arr_api[arr_max_index].length
for(i=0;i<len_max_arr;i++){ //for all dates in max length array
len_max_arr_j=arr_api.length
for(j=0;j<len_max_arr_j;j++){ //for all arrays
len_single_arr=arr_api[j].length
for(jj=0;jj< len_single_arr;jj++){ //for all dates in single array
if (arr_api[arr_max_index][i]["gasDayStartedOn"]==arr_api[j][jj]["gasDayStartedOn"] && isNaN(parseFloat(arr_api[j][jj]["gasInStorage"]))==false) {
gas_vol+=parseFloat(arr_api[j][jj]["gasInStorage"]);
gas_date=arr_api[j][jj]["gasDayStartedOn"];
}
}
}
gas_storage_temp.push([gas_date,gas_vol]);
gas_storage=gas_storage.concat(gas_storage_temp);
gas_storage_temp=[];
gas_vol=0;
}
console.log(gas_storage)
}