This question already has an answer here:
How to fix 'TypeError: Cannot call method "getRange" of null' in Google Apps Script
(1 answer)
Closed last year.
Im very new working with google script and APIs and Im trying to run a piece of code that makes the sheet in to a Json however I`m facing an issue where it says:
TypeError: Cannot read property 'getDataRange' of null
json # Code.gs:4
The code I`m using is the following:
function json() {
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet()
const sheet = spreadsheet.getSheetByName("APItest")
const data = sheet.getDataRange().getValues()
const jsonData = convertToJson(data)
return ContentService
.createTextOutput(JSON.stringify(jsonData))
.setMimeType(ContentService.MimeType.JSON)
}
I already tried to change the getSheetID but also didn`t work
Probably you're getting null value after the execution of
const sheet = spreadsheet.getSheetByName("APItest")
And That's why you get the error in the next statement. make sure that the sheet is not null.
Related
I'm and Old man trying to learn a new trick. 1st post. be merciful please. I keep getting this Message. Ive tried console logging it (line 13) get the same message.
All i want is to pull High low data from the openweather site for a designated city named in A2 of my spreadsheet.
The log isnt showing my API key or the location from the A2 location. ive looked at this for 2 hours and my eyes are crossing. Like i said im new. Im sure its something i have done wrong. Thanks in advance.
Message Exception: Invalid argument: http://api.openweathermap.org/data/2.5/weather?q={location}&appid=${key} (line 14, file "Code")
function getCurrentData() {
//API key
const key = "API key Here(actually a number)"
const ss = SpreadsheetApp.getActiveSpreadsheet()
const wsLocation = ss.getSheetByName("Location")
const wsLiveData = ss.getSheetByName("Live Data")
const location = wsLocation.getRange("A2").getValue()
const highCell = wsLiveData.getRange("B4")
const lowCell = wsLiveData.getRange("C4")
let apiURL = 'https://api.openweathermap.org/data/2.5/weather?q=${location}&appid=${key}'
//console.log(apiURL)
const resText = UrlFetchApp.fetch(apiURL).getContentText()
console.log(resText)
}
The issue appears due to fetching an invalid url.
Noting in the url that syntax ${} appears, you were attempting to define the url using template literals in a normal string.
To define a template literal string you should use the backtick character ( ` ) instead of quote character ( ' ).
More information about template literals can be found here:
Template literals (Template strings)
I'm accessing Google spreadsheet data from node.js as follows:
const sheets = google.sheets({version: 'v4', auth});
const res = await sheets.spreadsheets.values.get({
spreadsheetId,
range
});
const rows = res.data.values;
For reference, I'm using spreadsheets.values.get.
There is one cell with the value 9/24/2019. It's formatted as a date and is definitely not stored as a string. However, the value for that cell from the API call is "9/24/3019".
There are other cells with the same value that are correct. I checked the document version history, and this cell has never had any other value.
Anyone have any ideas what might be causing this and/or how to fix it?
First of all I'm using Vue.js to access data of an API using axios and a proxy
I'm trying to access the property of an object nested in the last array of several other arrays but I'm kinda hitting a wall, here's the detail :
Global details
the property I'm trying to access
I've tried different ways but here's my latest try :
axios
.get(proxyurl + history_url, {
reqHeaders
})
.then((reponse) => {
console.log(reponse.data)
this.lastItem = reponse.data.data.history[history.length-1]
console.log(this.lastItem)
this.lastEvol = this.lastItem.price
console.log(this.lastEvol)
})
The issue here is that the answer to "console.log(this.lastItem)" is :
lastItem answer
The value of the properties are now different and incorrect.
Since it's showing "Proxy" as the root object name I thought that may be the issue but I'm not sure.
I've tried several other ways to access this property but only had errors.
Any help would be greatly appreciated.
history is undefined in the history.length expression. Try this:
.then((reponse) => {
const history = reponse.data.data.history;
console.log(reponse.data)
this.lastItem = history[history.length-1]
console.log(this.lastItem)
this.lastEvol = this.lastItem.price
console.log(this.lastEvol)
})
function preprocessImage(img) {
const tensor = tf.fromPixels(img)
.resizeNearestNeighbor([224, 224]);
const croppedTensor = cropImage(tensor);
const batchedTensor = croppedTensor.expandDims(0);
return batchedTensor.toFloat().div(tf.scalar(127)).sub(tf.scalar(1));
}
the error i am getting is that tf.fromPixels is not a function . i wasnt getting this error as of two weeks back but i am suddenly getting this error on running the same code.
It looks like tf.fromPixels() has been removed and its function taken over by tf.browser.fromPixels().
Source
Am I using lodash.fp's convert method incorrectly? It seems like it doesn't work in the case of words
const fp = require('lodash/fp')
const assert = require('assert')
const words = fp.words.convert({ cap: false })
assert.equal(typeof words, 'function') // true as expected
// here I'd expect `words` to return a function that is expecting the
// remaining string argument
const splitByX = words(/[^x]+/g)
assert.equal(typeof splitByX, 'function')
published the above snippet here: https://runkit.com/lokua/lodash-fp-words-bug
I've also tried using fixed: false in the call to convert but get the exact same results.
This appears to be a bug to me, but I thought it better to post on StackOverflow before submitting a report in case my understanding of how convert works is off.
Here is a link to related issue asking how fp.words works, the answer was to use convert: https://github.com/lodash/lodash/issues/3397
using lodash#4.17.4