qeet / IMPORTJSONAPI

Use JSONPath to selectively extract data from any JSON or GraphQL API directly into Google Sheets.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sometimes response output in the cell below formula

zenminimalist opened this issue · comments

I think I've found an issue. If it's not a bug, I do apologize, as I'm not very technical.

If I use the following request:
=IMPORTJSONAPI("https://financialmodelingprep.com/api/v3/company/discounted-cash-flow/AAPL?apikey=demo";"$.";"dcf")

the output will be in the same cell as the formula.

But if you try this request:
=IMPORTJSONAPI("https://financialmodelingprep.com/api/v3/financial-growth/AAPL?limit=1&apikey=demo";"$..";"revenueGrowth")
it will list the results below the cell, which makes it impossible to have a list of stock on each row.

Is this intended behaviour?

Just to add (not sure if this is a separate issue or not)

This outputs nothing:
=IMPORTJSONAPI("https://fmpcloud.io/api/v3/discounted-cash-flow/AAPL?apikey=demo";"$.";"dcf")
but the same JSON output (if you look at the JSON response in the browser it's the exact same) from another provider gives a result:
=IMPORTJSONAPI("https://financialmodelingprep.com/api/v3/company/discounted-cash-flow/AAPL?apikey=demo";"$.";"dcf")

Seems strange to me. Maybe I'm missing something or it's my lack of fundamental basics of anything really technical. :)

commented

I think I've found an issue. If it's not a bug, I do apologize, as I'm not very technical.

If I use the following request:
=IMPORTJSONAPI("https://financialmodelingprep.com/api/v3/company/discounted-cash-flow/AAPL?apikey=demo";"$.";"dcf")

the output will be in the same cell as the formula.

But if you try this request:
=IMPORTJSONAPI("https://financialmodelingprep.com/api/v3/financial-growth/AAPL?limit=1&apikey=demo";"$..";"revenueGrowth")
it will list the results below the cell, which makes it impossible to have a list of stock on each row.

Is this intended behaviour?

The query should be:

=IMPORTJSONAPI("https://financialmodelingprep.com/api/v3/financial-growth/AAPL?limit=1&apikey=demo","$.[*]","revenueGrowth")

This will give you the expected result.

Thanks. Maybe it's just my sheet, but if you use your query:
=IMPORTJSONAPI("https://financialmodelingprep.com/api/v3/financial-growth/AAPL?limit=1&apikey=demo","$.[*]","revenueGrowth")
then go to the cell right below it and enter something you get an error.
I've made a quick gif of the said behavior. https://imgur.com/a/z2ZSeHN

So the results seem to add something additional to the cell below. Hence you're not able to add an additional ticker row below as this would result in the error attached.

commented

Just to add (not sure if this is a separate issue or not)

This outputs nothing:
=IMPORTJSONAPI("https://fmpcloud.io/api/v3/discounted-cash-flow/AAPL?apikey=demo";"$.";"dcf")
but the same JSON output (if you look at the JSON response in the browser it's the exact same) from another provider gives a result:
=IMPORTJSONAPI("https://financialmodelingprep.com/api/v3/company/discounted-cash-flow/AAPL?apikey=demo";"$.";"dcf")

Seems strange to me. Maybe I'm missing something or it's my lack of fundamental basics of anything really technical. :)

The two results are not exactly the same. The first source returns the data within an array whilst the second does not. The following will work for the first source:

JSONAPI("https://fmpcloud.io/api/v3/discounted-cash-flow/AAPL?apikey=demo","$.[*]","dcf")

commented

Thanks. Maybe it's just my sheet, but if you use your query:
=IMPORTJSONAPI("https://financialmodelingprep.com/api/v3/financial-growth/AAPL?limit=1&apikey=demo","$.[*]","revenueGrowth")
then go to the cell right below it and enter something you get an error.
I've made a quick gif of the said behavior. https://imgur.com/a/z2ZSeHN

So the results seem to add something additional to the cell below. Hence you're not able to add an additional ticker row below as this would result in the error attached.

Okay try this:

=IMPORTJSONAPI("https://financialmodelingprep.com/api/v3/financial-growth/AAPL?limit=1&apikey=demo","$.[0]","revenueGrowth")

=IMPORTJSONAPI("https://financialmodelingprep.com/api/v3/financial-growth/AAPL?limit=1&apikey=demo","$.[0]","revenueGrowth")
That works, thanks.

Also, I've found another way how not to "overwrite" the cell below it. If I change it to $[*] instead of $.[*] it does not overwrite. Even though I don't understand why (it's because I still have a really hard time understanding the syntax behind JSON), it works 👍

@qeet Is there any way to get back complete following response

[
  "AAPL",
  "EMC",
  "HPQ",
  "DELL",
  "WDC",
  "HPE",
  "NTAP",
  "CPQ",
  "SNDK",
  "SEG"
]

(https://finnhub.io/docs/api/company-peers)

I know from your previous answer that you have to specify every path you want back from JSONAPI and that's been working fantastic for me, especially as I'm getting back real raw data, unlike the hit & miss with the old importJSON.
But I'm having trouble with the JSON response from above as there's no description for the path such as "symbols" etc. I've tried

=IMPORTJSONAPI("https://finnhub.io/api/v1/stock/peers?symbol="&C2&"&token="&'Settings & Links'!$K$19;"$[*]";"@")
and tried alteratation of the @ symbol e.g. $, [*], 1,2,.. etc.

commented

@zenminimalist. Try this:

=IMPORTJSONAPI("https://finnhub.io/api/v1/stock/peers?symbol="&C2&"&token="&'Settings & Links'!$K$19;"$";"[0], [1], [2]")

Thanks, that worked. Sometimes it's easier then one thinks : )