Google new spreadsheets return JSON - json

I am using this link to return JSON data, but it is not working now. It shows a "Invalid query parameter value for grid_id" error. Any ideas? Thanks.
https://spreadsheets.google.com/feeds/list/1fe--KCLag0QNEuYqSeBU2HPZLUoyvicxYfoONnglx-k/821619139/public/values?alt=json
reference link
Google Spreadsheets retrieving JSON feed

Something recently changed in how google assigns the codes for each worksheet. For me, the key was to change the first worksheet from "0" to "od6".
The way to look them up is to use https://spreadsheets.google.com/feeds/worksheets/YOUR-SPREADSHEET_ID_HERE/public/basic. If I do that with your spreadsheet (https://spreadsheets.google.com/feeds/worksheets/1fe--KCLag0QNEuYqSeBU2HPZLUoyvicxYfoONnglx-k/public/basic), I see that the only worksheet id listed is "odl6521" - "821619139" no longer exists. But if I go to https://spreadsheets.google.com/feeds/list/1fe--KCLag0QNEuYqSeBU2HPZLUoyvicxYfoONnglx-k/odl6521/public/values?alt=json , I get out a json file that looks to be what you want.
Hope that helps!

Related

Google DataStudio REGEX_EXTRACT json

I am trying to create a new field by creating a calculated field and parsing some json in Google DataStudio. However I keep getting an error saying Failed to fetch data from the underlying data set if I use REGEX_EXTRACT
formula I am using:
REGEXP_EXTRACT(json,'(?<="received_at":")(.*?)(?=")')
json string:
{"end_device_ids":{"device_id":"eui-a81758fffe0600cc","application_ids":{"application_id":"3cc54cfd-a809-42e3-89bb-4497ec67fe42"},"dev_eui":"A81758FFFE0600CC","join_eui":"0000000000000000","dev_addr":"260B1B1E"},"correlation_ids":["as:up:01FG833XJCCNBGDDNDYDRV9SRR","gs:conn:01FG16JYQBRKZC3K8HXE6CWK89","gs:up:host:01FG16JZSSC6GWA8TNY733T5GK","gs:uplink:01FG833XBKQGR83P9MTXSEQQHE","ns:uplink:01FG833XBR0NHHAM079T00ZC76","rpc:/ttn.lorawan.v3.GsNs/HandleUplink:01FG833XBR8SJYB9BMX8ZC61YY","rpc:/ttn.lorawan.v3.NsAs/HandleUplink:01FG833XJBN6BQX9HP4MYK51YR"],"received_at":"2021-09-23T01:08:02.252783252Z","uplink_message":{"session_key_id":"AXvkNZkkbAdO+pD5hVSLXg==","f_port":5,"f_cnt":1230,"frm_payload":"AQDoAjwHDjY=","decoded_payload":{"humidity":60,"temperature":23.2,"vdd":3638},"rx_metadata":[{"gateway_ids":{"gateway_id":"iot-stadslab-1","eui":"A84041FFFF1F9951"},"time":"2021-09-23T01:08:06.175212Z","timestamp":2063422380,"rssi":-125,"channel_rssi":-125,"snr":-8.2,"location":{"latitude":51.69522207692182,"longitude":5.293667793175701,"altitude":15,"source":"SOURCE_REGISTRY"},"uplink_token":"ChwKGgoOaW90LXN0YWRzbGFiLTESCKhAQf//H5lREKyn9dcHGgsI8qavigYQroDmECDgr7vshpo1","channel_index":4}],"settings":{"data_rate":{"lora":{"bandwidth":125000,"spreading_factor":10}},"data_rate_index":2,"coding_rate":"4/5","frequency":"867300000","timestamp":2063422380,"time":"2021-09-23T01:08:06.175212Z"},"received_at":"2021-09-23T01:08:02.040299926Z","consumed_airtime":"0.370688s","network_ids":{"net_id":"000013","tenant_id":"ttn","cluster_id":"ttn-eu1"}}}
My regular expression is working as expected inside Regex101. Why is my formula not working? If I try to manually add a column in google sheets using the REGEXEXTRACT(A2, "(?<=\"received_at\":\").*?(?=\")") function I am also getting an error that tells me nothing. Any solution to my problem is appreciated.
Thank you in advance.
Your regex is
=regexextract(A2,"""received_at"":"".*?""")

How to use ImportJSON to pick the BTC Latest Price from BitBNS?

I am trying to ImportJson function on my Google sheet to pull their Public Information of latest BTC Price.
But, I am not able to get it work.
Following is their Public Json Format Http Request URL:
https://bitbns.com/order/getTickerWithVolume/
Following is the ImportJSON function I am trying:
=importJSON("https://bitbns.com/order/getTickerWithVolume","/BTC","0.last_traded_price")
Please note: I am already installed the IMPORTJSON script in Google Sheet and I able to pull data from other Public API address.
Question 1:
You want to retrieve the value of last_traded_price in the object of BTC from the URL of https://bitbns.com/order/getTickerWithVolume/ using ImportJSON.
I could understand like above. If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
Modified formula:
=importJSON(A1,"/BTC/last_traded_price", "noInherit,noTruncate,noHeaders")
https://bitbns.com/order/getTickerWithVolume is put in the cell "A1".
In this case, /BTC/last_traded_price is used as the path.
Result:
Reference:
ImportJSON
Question 2:
You want to retrieve the latest value of p from the object of https://public.coindcx.com/market_data/trade_history?pair=B-BTC_USDT.
When I saw the object of https://public.coindcx.com/market_data/trade_history?pair=B-BTC_USDT, it was found that the 1st index of the array is the latest value. By this, how about the following sample formula?
Sample formula:
=INDEX(importJSON(A1, "/p","noInherit,noTruncate,noHeaders"),1)
https://public.coindcx.com/market_data/trade_history?pair=B-BTC_USDT is put in the cell "A1".
Note:
In above 2 answers, I think that above answer might not be able to be used for other objects with the other structure except for the objects retrieved by above URLs. Please be careful this. I apologize that I cannot propose one formula which can be used for the objects with the various structures.

Issue with body.replaceText() in Google Docs

I am populating a Google Doc template based on a Google Form submission. Upon submit, the program copies the template Google Doc, captures the first item from the Google Form which is always the person's name (because this is a required field), and then replaces {{Name}} in the new file with the entered name using:
var name = itemResponses[0].getResponse();
body.replaceText('{{Name}}', name);
That works correctly. But then I iterate through the rest of the item response and not all the items are required, so I use a lookup table in a Google sheet. The loop takes the item id in the item response and then looks up the text that the response will replace. Then the program does:
var textToReplace //this value is from column B in the Google Sheet lookup table
var newText //this value is the entered response from the Google Form
body.replaceText(textToReplace, newText);
When I do this, I am getting a "Exception: Invalid argument: searchPattern" error. Why are these two body.replaceText() functions different? They are both finding a variable with in double brackets in the Google doc, but it only works in one case.
And to be clear, this was previously working correctly for the last couple of months and only recently started to not work (maybe Google changed something??). My hypothesis is that it has to do with a regex pattern in the first parameter of replaceText.
The "searchPattern" error is a good clue, in certain circumstances, it tells us the value of "textTopReplace" is not a valid search pattern. Since the code hasn't changed, the lookup table in your spreadsheet, or the fields on the form probably have.
One of your lookups is returning a value that isn't a valid search pattern. Perhaps it is returning Null, or an empty string?
You can get more information by using console.log to log debug info to the stackdriver log interface provided by Google, like so:
console.log('text to replace: "'+textToReplace+'"'); //this value is from column B in the Google Sheet lookup table
console.log('value: "'+newText+'"'); //this value is the entered response from the Google Form
body.replaceText(textToReplace, newText);
Then, to view the logs, select "stackdriver logging" from the View menu.

Retrieve Google Spreadsheet Worksheet JSON

I try to receive the JSON of a Google Spreadsheet Worksheet. It worked till some days ago. For the default worksheet it still works, but not for all other worksheets.
This is the working URL for the default worksheet: https://spreadsheets.google.com/feeds/list/1caRqAA1TyBoZ0eVZvvKheEBh9SGRmQII4qih9urY70k/od6/public/full?alt=json
And this is the URL for the worksheet that stopped working: https://spreadsheets.google.com/feeds/list/1caRqAA1TyBoZ0eVZvvKheEBh9SGRmQII4qih9urY70k/1416241220/public/full?alt=json
The error message is Invalid query parameter value for grid_id.
Only difference is the worksheet parameter (od6 vs 1416241220).
Any ideas on why that error suddenly occurs?
ChrisPeterson's note:
You can use worksheet position number (1 for the first/default worksheet, 2 for the second worksheet).
Original answer
I came across the same issue and I managed to find my way out.
It seems that they recently changed the id for each worksheet.
You can find the new ID at the following
https://spreadsheets.google.com/feeds/worksheets/YOUR_SPREADSHEET_ID/private/full
I got something like o3laxt8 between <id> tags
Ps: od6 anddefault values will always work and redirect to the first worksheet of your document.
Joe Germuska' note:
od6 doesn't work anymore
Seems to work again.
I'd like to share a concrete example because I find there are enough confusing instructions out there including the accepted answer and worksheet IDs and where to put them not being obvious.
Here's a document I published and anyone with the link can view:
https://docs.google.com/spreadsheets/d/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/edit?usp=sharing
The document has to be published correctly. There are two Publish buttons and the first one doesn't work for this task. Use the second.
The document KEY is important. Obtain the KEY from between the /d/ and the /edit in the url. In my example, the key is 1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c.
Second, use the following URL style, replacing KEY with your own:
https://spreadsheets.google.com/feeds/list/KEY/od6/public/values?alt=json
My example url links directly to published json:
https://spreadsheets.google.com/feeds/list/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/od6/public/values?alt=json
Finally, if the worksheet has multiple sheets (or tabs), replace od6 in the url with a number. My example has two tabs, so there are two urls corresponding to either tab. I simply replace od6 with 1 and 2 depending on the order of the sheets:
Tab 1:
https://spreadsheets.google.com/feeds/list/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/1/public/values?alt=json
Tab 2:
https://spreadsheets.google.com/feeds/list/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/2/public/values?alt=json
In the event of a worksheet where the tabs are reordered frequently, it is possible to get the ID of a given sheet and use that instead of ordered numbers. I first learned of this approach from this post or this post:
In brief, you would reform a private URL with your KEY:
https://spreadsheets.google.com/feeds/worksheets/KEY/private/full
This only works on a browser where you are logged into Google Drive on an account with permissions.
Next, you have to sift through XML to find your sheet IDs:
Replace the previous 1 and 2 with the IDs, for example:
Tab 1 (first worksheet id in a new google sheet is always od6 by default, no matter order of tabs):
https://spreadsheets.google.com/feeds/list/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/od6/public/values?alt=json
Tab 2:
https://spreadsheets.google.com/feeds/list/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/ope57yg/public/values?alt=json
You can find the new ID at the following
https://spreadsheets.google.com/feeds/worksheets/YOUR_SPREADSHEET_ID/private/full

Is it possible to combine a Google Spreadsheets JSON request with a data query?

I have successfully used the information in the link below to get a JSON output from a Google spreadsheet.
https://developers.google.com/gdata/samples/spreadsheet_sample
Is it possible to combine this JSON request with a data query, such as those seen in the link below this?
https://developers.google.com/chart/interactive/docs/querylanguage
Yes. Use the new url for accessing google docs:
https://docs.google.com/spreadsheets/d/%KEY%/gviz/tq?gid=%GID%&tq=%QUERY%
%KEY% and %GID% can be found in your spreadsheet's url, and %QUERY% is whatever you are asking the sheet for. For example, you might ask it to look up a phone number in column B by looking for a name in column A by passing "B where A = 'John Smith'" as the %QUERY%.
seems like it doesn't need the GID parameter :D