Savad
Savad

Reputation: 1316

How to get return from value from a google script url in javascript

The code below is my google script code. When I simply paste the URL on the browser it is returning a value. but when I try to get the value using javascript. it returns null

Google script

function doGet(e) {
  var array = SpreadsheetApp.openById('1qwSU2YVuGea3Dg06yUpUkyhV1Hn-Qf3YshgZkEnJoBo')
  .getSheetByName('Sheet1').getRange('A1:A1').getValues();
  
  return ContentService.createTextOutput(array[0]);
}

Javascript

var url_string = "https://script.googleusercontent.com/macros/echo?user_content_key=1AxKHAUiqHNfdbnLALqbmxIoGLQuLR7qjSR7NxCDxgyqacFzuIovzOSyRyu0xkwpe7TF7qJcKknkuPYhV_apY6L9ikxPUB7em5_BxDlH2jW0nuo2oDemN9CCS2h10ox_1xSncGQajx_ryfhECjZEnMy8zAZf_PeEgqhQVTSu0Ty9Drtp1yaLkXH9-vnTbcP-gooKnCg3eBY8k9BT1tmvR4PZc_4F8_fJkoGWxUlugKqNYjOEVPmtwA&lib=M9OCNb7KeZyOBiWrcHIwQiTdKF1_8u-qf"; 
var url = new URL(url_string);
var c = url.searchParams.get("");
var c = url.
console.log(c);
alert(c);

Upvotes: 0

Views: 377

Answers (1)

Cooper
Cooper

Reputation: 64062

Access it with UrlFetchApp.fetch() using method = "Get" and then use response.getContentText() to get the return.

Upvotes: 1

Related Questions