0

I am using the below script to call data from Spreadsheet, But I face error showing "Exception: Invalid argument:" in log

function myFunction() {
  
const key = "606503c07f32a32677df7e0f"
const ss= SpreadsheetApp.getActiveSpreadsheet()
const wsLocation = ss.getSheetByName("Location")
const wsLiveData = ss.getSheetByName("Live Data")

const location = wsLocation.getRange("A2").getValue()
const units = wsLocation.getRange("B2").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}&units=${units}'

const resText = UrlFetchApp.fetch(apiURL).getContentText()
console.log(resText)

}

Please help me to call location, units and key in apiURL. Currently I called using ${location}

Ron M
  • 5,791
  • 1
  • 4
  • 16
Moses
  • 214
  • 1
  • 4
  • 12

1 Answers1

1

Try replacing the single quotes in the apiURL with back quotes:

`https://api.openweathermap.org/data/2.5/weather?q=${location}&appid=${key}&units=${units}`

and see if that helps?

JPV
  • 26,499
  • 4
  • 33
  • 48