Reputation: 15
I'm having trouble with the fetchAll method for UrlFetchApp.
I'm currently running multiple functions to gather api data from a handful of links with slight variations in api actions. All functions are returning and parsing data under consistent JSON fields. I want to have one function to retrieve the api data at once, parse once, and output once. I thought fetchAll would be the better method of doing this. The output will be to a spreadsheet.
Below is a variation of the script simplified for privacy. I keep getting "Cannot find method fetchAll(object,object)" error at line 14. I have tried fetching the urls with UrlFetchApp.fetchAll[eth,btc] and this gets me past the error but then "Cannot call method 'getContentText' of undefined".
Can't seem to figure out the correct way to do this from the Google Apps documentation. No help from google discussion group so far.
Do I need to incorporate the parse as an object within the fetchAll method?
function dailyhx() {
var ss = SpreadsheetApp.getActive().getSheetByName('DailyHx');
var eth = {
'url' : 'https://min-api.cryptocompare.com/data/histoday?fsym=ETH&tsym=USD&limit=10',
'method' : 'get',
'contentType' : 'application/json',
};
var btc = {
'url' : "https://min-api.cryptocompare.com/data/histoday?fsym=BTC&tsym=USD&limit=10",
'method' : 'get',
'contentType' : 'application/json',
};
var mph = UrlFetchApp.fetchAll(eth, btc)
var j1 = JSON.parse(mph.getContentText());
Loager.log(j1)
}
Upvotes: 1
Views: 2784
Reputation: 8964
The UrlFetchApp.fetchAll()
function only expects one parameter which must be an array.
So replace this:
var mph = UrlFetchApp.fetchAll(eth, btc);
with this:
var requests = [eth, btc];
var mph = UrlFetchApp.fetchAll(requests);
Upvotes: 4