I need to replicate the =IMAGE(url)
functionality but calling it with a custom header param
Basically adding into the cell =FETCHIMAGE()
and getting it to return the image in the cell – but the image is called from an api that needs a Referer header to access it
I’m new to GAS, but it seems the best way would be something like the following:
/**
* Fetches an image with custom header param and inserts into the cell it's called from
*
* @customfunction
*/
function FETCHIMAGE(){
let ss = SpreadsheetApp.getActiveSpreadsheet()
let sheet = ss.getSheetByName('Sheet1')
let cell = sheet.getActiveCell()
let imgUrl = '...'
let headers = {Referer: '...'}
let response = UrlFetchApp.fetch(imgUrl)
let image = response.getBlob()
// 1.
cell.setValue(image); // errors out due to permission from custom function
// 2.
return image // doesn't work
}
Does anyone know how to either parse the image properly to get it to return, or set it in the cell from the custom function?
Thanks!