Home > Blockchain >  In Google Sheets, how can I output an array of IMPORTJSON() calls using a column as reference?
In Google Sheets, how can I output an array of IMPORTJSON() calls using a column as reference?

Time:07-07

I hope the question is clear, if not let me know so I can rewrite.

I am using IMPORTJSON() from Github:
enter image description here

But I'm getting some errors. ATM its displaying:

Exception: Request failed for 
https://api-apollo.pegaxy.io returned code 404. 
Truncated server response: <!DOCTYPE html> <html lang="en">
     <head> 
        <meta charset="utf-8"> 
        <title>Error</title> 
        </head> 
    <body> 
        <pre>Cannot GET /v1/pegas/923195,https://api-apo... 
            (use muteHttpExceptions option to examine full response) 
            (line 217). 

Another thing I tried, check Sheet2, was to simplify the call with this:

=ARRAYFORMULA(ImportJSON({E2:E}))

Where E2:E is the list of URLs built with HYPERLINK(). With this I also get an error:

Exception: Limit Exceeded: URLFetch URL Length. (line 217).

So maybe ÌMPORTJSON() does not allow for building an array?
Is there a work around for this situation or is there something wrong with my formulas?

Demo file here:
enter image description here

CodePudding user response:

You can support arrays on any custom function using Array.map:

/**
 * Adapts importjson to support arrays
 * Restriction: A url should only return one value
 *
 * @customfunction
 */
const importjsonArray = (urls, ...args) =>
  Array.isArray(urls)
    ? urls.map((url) => importjsonArray(url, ...args))
    : String(ImportJSON(urls, ...args));
  • Related