To retrieve stock price using Google Apps Script, you can use the UrlFetchApp service to make a request to the Google Finance API and parse the JSON response to extract the price.
Here's an example code snippet to get the stock price of Apple:
function getStockPrice() {
var symbol = "AAPL";
var url = "
https://finance.google.com/finance/quote/" + symbol + ":NASDAQ?output=json";
var response = UrlFetchApp.fetch(url);
var content = response.getContentText();
var json = JSON.parse(content.substring(6));
var price = json[0].l;
return price;
}
In this example, the symbol variable is set to "AAPL" for Apple, but you can change it to the stock symbol of your choice. The url variable is constructed with the symbol and the exchange (in this case, NASDAQ), and the UrlFetchApp.fetch() method is used to make a GET request to the URL.
The response content is then parsed as JSON using JSON.parse() method, and the price is extracted from the parsed JSON object using the l property.
You can then call the getStockPrice() function in your Google Apps Script to retrieve the stock price.