I am making a Google Sheet that gets info from an API.
In Google Script, I want to send the text
part of the response only to my cell.
function myFunctionPost() {
var ss = SpreadsheetApp.getActiveSheet();
var input = ss.getRange(2,2).getValue();
var url = "https://www.whatever.com/example/api";
var data = {
"prompt": input
};
var payload = JSON.stringify(data);
var headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Bearer MY_API_KEY"
};
var options = {
"method": "POST",
"headers": headers,
"payload": payload
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response);
var output = response.getContentText();
ss.getRange(3,2).setValue([output]);
}
Current output:
{"text":"good text and yes","second":true,"third":"bad text and no"}
Desired output:
good text and yes
How to I select only the text
?
I could extract it using formulas, but I rather do it cleanly in the script.