I am working on a chrome extension that gets some variables from a google sheets spreadsheet. I finally got the api setup correctly and can successfully query the data for the first variable from a cell in that spreadsheet. The problem for me is I am not familiar with the format the data is in.
Here is my code to query the google spreadsheet:
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://sheets.googleapis.com/v4/spreadsheets/*spreadsheetID*/values/A2?key=*API Key*", false);
xhr.send();
var result = xhr.responseText;
The output I receive is:
{
"range": "Sheet1!A2",
"majorDimension": "ROWS",
"values": [
[
"https://www.access.com/home/"
]
]
}
the URL https://www.access.com/home is what I am trying to parse from the spreadsheet. If I change the code to parse the responseText in json I can get the value for range, just not for the "values" data to get the URL:
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://sheets.googleapis.com/v4/spreadsheets/*spreadsheetID*/values/A2?key=*API Key*", false);
xhr.send();
var result = JSON.parse(xhr.responseText);
var data = result.range;
What am I doing wrong and how do I correctly parse the URL?
*While the post at Access / process (nested) objects, arrays or JSON does a great job at explaining how to access nested objects that are named, I was unable to figure out that how to access the nested array in my object because it didn't have a name.