API coingecko data - doNotDelete - api

I use Coingecko's importJSON code to load data into a Google Sheet. The last parameter of the url (see below) is called 'doNotDelete!$A$!'. If I run the importJSON function in my sheet a numeric value in cell A1 of the tab doNotDelete shows up. What does this number mean? Is it the number of seconds that past since last execution? There is no explanation about it in the Coingecko's article about their API ImportJSON function for Google Sheets.
=ImportJSON("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=250&page=2&sparkline=false","/name,/current_price,/market_cap,/price_change,/total_volume,/high_24h,/low_24h","noTruncate,noHeaders",doNotDelete!$A$1)

When the value of this cell changes ImportJSON gets updated values from the API. It doesn't have any meaningful value, your autorefresh script should change that to a random value whenever it is run.
It's not coingecko's script, it is from here and it is currently unmaintained, so if google changes the behavior of any of the used functions it can stop working.

Related

How to retrieve specific column value in string format through google sheets API?

We have multiple columns in our google excel sheet as below,
image1
We are trying following API call,
https://sheets.googleapis.com/v4/spreadsheets/7dj1kU54fgrhQk46uMrqq-W-QMlBq45kjiuEdhfjm5zE5gNvUoLk/values/'sheet1'!A2:O200?dateTimeRenderOption=SERIAL_NUMBER&valueRenderOption=UNFORMATTED_VALUE&majorDimension=ROWS
By hitting the above call, we get the output as below,
image2
But, we want the value of column Currency same as available in the sheet. That is $667 where as we just get 667 by the above API call.
If we just replace the value of valueRenderOption with FORMATTED_VALUE, we get the output as below,
image3
But, then it returns the value of all columns as formatted. We just want to get the value particular column as FORMATTED_VALUE. Is there any by which we can do this?
Unfortunately not - you need to make two API calls if you want different cells to have different ValueRenderOptions. This is a limitation of the API itself, as the specified ValueRenderOption must be the same for the whole range in a single call.

How can I check the time a cell was edited and set the time and date in other cells? Google script

I have spreadsheet and I'm basically going to use it for inventory tracking and management.
In one sheet I'll have an app on my phone fill a list when it reads
a QR code.
In the second sheet there is also a list with the
specific QR codes of each item.
I need to know when a cell in the first sheet has been updated and put that information in the following two cells.
I'm using this trigger to check if ANY cell in the document has been updated.
function cellEditTrigger()
{
ScriptApp.newTrigger('coolFunction').forSpreadsheet('awsomeSpreadsheetID').onEdit().create();
}
It works fine and it runs the 'coolFunction' function. However I can't seem to be able to get the time and date for the cells that have been edited and put that information in the next two cells.
I know I could use onEdit(e), but I still can't get the information from e.range and I would like my script to not have to be bound to the Spreadsheet.
Is there any way to accomplish this?

How to make "getValue()" working for me again

I have an existing google spreadsheet + script which was working perfectly. But suddenly stopped working since 1 week back.
In a sheet of my spreadsheet I am using the following command to download 200 days of historical stock prices:
=googlefinance(B1,ʺcloseʺ,today()-200,today()) ; //cell B1 contains the ticker symbol. It populates the values from cell B3 – B142
Now I have a script, in which I am first setting the value of cell B1. Wait for 10 seconds. Then I extract the value of a specific cell (containing a historical price).
var xyz = sheet.getRange('B100').getValues();
This line is not working. When I print the value of xyz it is always empty. However if I pull any other static value from the sheet, I get the value correctly. Any insights, very appreciated.
This is unfortunately not supported through the Sheets API or scripts. See https://gsuiteupdates.googleblog.com/2016/09/historical-googlefinance-data-no-longer.html for details.

Finding last written row in Google Spreadsheet API

Is there any way to find the last row you have written in a google spreadsheet in Java?
I tried to do that by having a variable which I keep in another file and I update that every time I do another writing. Is there any other way?
Finding last written row in Google Spreadsheet API
I'll give you a concept first using REST calls but you'll have to apply that in Java.
Exceed the range of cells where you're writing.
So to find last written row between cells A1:A10, use the range A1:A11 or A1:B (using B means all the rows in cell A will be traversed).
Fetch a range of cells, using GET. Parse the response result. And get the length of the parsed values. The length will always indicate the last row since Sheetsv4 ignores blank/empty cells.
So example I have a range of cells between A1:A10. I wrote "hello" in A10. Following the concepts above I do this:
..
xhr.open('GET', 'https://sheets.googleapis.com/v4/spreadsheets/'+myspreadsheetId+'/values/Sheet1!A1:A10);
..
xhr.onload = function (oEvent) {
arrayBuffer = xhr.response;
myArray = JSON.parse(arrayBuffer);
console.log("last row is " + myArray.values.length)
.. //output is 'last row is 10'
This part of my XHR request returns 10. Now I know that the last written row in my sheet is A10.
To do this in Java use the solution based on this SO thread.
mService.spreadsheets().values().get("ID_SHEET", "Sheet1!A1:B").execute();
Also check this thread about writing on data cells using Java. I think it offers additional insight as well.

Google Apps Script on Form Submit Time Formatting Glitch/Fix

Background:
How: I suspect that this is a glitch within Google Form (submission process)/Spreadsheet, but may be part of the Date conversion utility of the Spreadsheet interface (and is an intended feature).
When entering a format in a text box in Google Forms, there is some sort of communication error between the Form submit and Response Spreadsheet, or pre-processing of the Form's data before it is sent to the spreadsheet. The glitch only seems to happen for data in a text field of the format ##:## TEXT where TEXT contains no '.' characters. For example: 4:15 pm will reproduce the glitch, but 4:15 p.m and 4:15 p.m. will not.
Result: An apostrophe character is added to the beginning of the string when it is put into the Spreadsheet (i.e. '4:15 pm) which throws off several sub-systems I have in place that use that time data. Here are two screenshots (sorry for the bad sizing on the second):
I'm 99% certain that the glitch is caused by the ##: combination.
Temporary Fix?: The real question is... how might I go about removing that pesky apostrophe before I start manipulating the time data? I know how to getValue() of a cell/Range. Assume I have the value of a cell in the following manner:
var value = myRange.getValue();
// value = '4:15 pm
How can I go about processing that value into 4:15 pm? A simple java function could be
value = value.substring(1); // Assuming "value" is a String
But in Google App Scripts for Spreadsheets, I don't know how I would do that.
Post-Script: It is necessary to post-process this data so that I don't have to lecture university faculty in the language department about inputting time format correctly in their forms.
Thanks in advance to those who can help!
How can I go about processing that value into 4:15 pm? A simple java
function could be
value = value.substring(1); // Assuming "value" is a String But in
Google App Scripts for Spreadsheets, I don't know how I would do that.
Google Apps Scripts uses Javascript which has the exact same method.
value = value.substring(1);
should return all except the first character.
More about Javascript substring at: http://www.w3schools.com/jsref/jsref_substring.asp
If you remove the ' in the spreadsheet cell the spreadsheet interface will convert this entry to a date object.
This might (or not) be an issue for you so maybe you should handle this when you read back your data for another use...
It doesn't happen when text is different (for example with P.M) simply because in this case the ' is not necessary for the spreadsheet to keep it as a string since the spreadsheet can't convert it to a date object (time value).
Artificial intelligence has its bad sides ;-)
edit :
You cant do this in an onFormSubmit triggered function using the javascript substring() you mentioned. If you're not familiar with that, here is the way to go :
To run a script when a particular action is performed:
Open or a create a new Spreadsheet.
Click the Unsaved Spreadsheet dialog box and change the name.
Choose Tools > Script Editor and write the function you want to run.
Choose Resources > Current project's triggers. You see a panel with
the message No triggers set up. Click here to add one now.
Click the link.
Under Run, select the function you want executed by the trigger.
Under Events, select From Spreadsheet.
From the next drop-down list, select On open, On edit, or On form
submit.
Click Save.
see doc here and here