Can Google Apps Script process GET query string and post to Google Sheets? - google-apps-script

I'm trying to learn Apps Script. I wonder if it is possible for a script to receive GET requests and then enter the query string values to a Google Sheet.
For example, if we execute this command:
$ curl https://script.google.com/d/xxx-xxx-xxx/?header1=value1&header2=value2&headerN=valueN
Then we could expect a Google Sheet to be populated with column headers header1, header2, up to headerN along with rows of values from the query string.
Would this be possible? A simple sample Apps Script will be appreciated.

Yes :) This is possible. Please refer to the request parameters > e.queryString.
I suppose, that should do the trick but please feel to come back here again in case you require further clarifications.

Related

Create a Apps Script that will send email notification based on a Google Form response or what is entered in the cell in Sheets

I have never used Apps Script but I think I have a need now that this might help with. I am trying to figure out how to get a google form (or the response sheet) to send an email notification depending on the answer to a question (or what is entered in the attached responses sheet in the cell for the question). Depending on the response I need to send an email to different people. Is that possible with Apps Script and could someone give me some pointers? Any help would be appreciated.
I am not a programmer so I was looking for some scripts and Youtube videos that I could possibly edit but so far everything I have tried to edit result in an error.

importing api into google sheets

I am wanting to use an api to import sunrise and sunset times into a google sheet.
I found this api: https://sunrise-sunset.org/api
I am new to using functions and was wondering if someone could point me in the right direction on how exactly to get my desired results.
Cheers
When I saw your provided URL, it seems that the result values are returned as a JSON data. In this case, when Google Apps Script is used, the JSON data can be easily parsed. So, how about the following sample script?
Sample script:
Please copy and paste the following script to the script editor of Google Spreadsheet and save the script. When you use this script, please put a custom function like =SAMPLE("https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400&formatted=0") to a cell. By this, the script is run and the result value is obtained.
function SAMPLE(url) {
const res = UrlFetchApp.fetch(url).getContentText();
const obj = JSON.parse(res);
const values = ["sunrise", "sunset"].map(e => [e, new Date(obj.results[e])]);
return values;
}
In this sample script, the date string is parsed as the date object. So, please include formatted=0 to the query parameter of the endpoint like https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400&formatted=0. When this query parameter is used, it seems that the date string is returned as ISO 8601. So, I used this.
Testing:
When this script is tested, the following result is obtained. In this case, the result value is put as the date object.
Note:
When you put =SAMPLE("https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400&formatted=0") to a cell, an error occurs, please reopen Spreadsheet and test it again.
From I am new to using functions and was wondering if someone could point me in the right direction on how exactly to get my desired results., this is a simple sample script for explaining the script. So please modify this sample script for your actual situation.
References:
Sunset and sunrise times API
Custom Functions in Google Sheets
fetch(url, params)

How do I deploy my apps script into my google sheets

I have written a google apps script which sorts 2 columns in a sheet and I want it to always be running when the sheet is updated by a jotform submission. The script works fine when i test it but I've tried to 'deploy' it into the sheet without success.
I tried to deploy it as a web-app and and add-on but am not sure if they're the correct type of 'deployment'. Is there another step I'm missing to make my script 'go live'?
Some guidance on this would be appreciated. Thanksenter image description here
I don't fully understand your question but I think you mean you want your function to be called from within a cell? An example from Google's documentation is as follows:
#1: Create and name your function:
function DOUBLE(input) {
return input * 2;
}
#2 Then write the function directly into the cell as you would with =SUM():
=DOUBLE(A1)
If this is (and sorry if it isn't) what you're trying to do, then you don't need to deploy the script or anything extra like that. Just save it and it should start to work.
Reference:
https://developers.google.com/apps-script/guides/sheets/functions

Is it possible to use IMPORTXML function and modify it with a query?

I am creating a spreadsheet portfolio. I came across some limitation, e. g. that I can not automate the process of importing the data from a website for different stocks. This is since the Index for the stock information on the website is often different from another stock. However there is the pattern that it is the next Index from a defined string e. g. "Branche". This made me wonder if I can automate the process with the Google Apps Script.
I wrote down the steps at first in Google Sheets. Then I formulated the steps in the Google Apps Script. Now I am stuck.
Step 1
=IMPORTXML("https://www.comdirect.de/inf/aktien/detail/uebersicht.html?ID_NOTATION=9386126";"//tr/td[#class='simple-table__cell']")
Step 2
=IMPORTXML(CONCATENATE("https://www.comdirect.de/inf/aktien/detail/uebersicht.html?ID_NOTATION=";"9386126");"//tr/td[#class='simple-table__cell']")
Step 3
=INDEX(IMPORTXML(CONCATENATE("https://www.comdirect.de/inf/aktien/detail/uebersicht.html?ID_NOTATION=";"9386126");"//tr/td[#class='simple-table__cell']");62;1)
Step 4 final product - just an idea not working yet
function import_branche() {
var url1 = "https://www.comdirect.de/inf/aktien/detail/uebersicht.html?ID_NOTATION="
var ulr2
var ticker = "//tr/td[#class='simple-table__cell']"
Index = find the INDEX with the String == "Branche"
return Index(IMPORTXML(CONCATENATE(url1;url2); ticker);(Index+1);1)
}
Ideally, I would like to have a function where I only need insert the link of the website and get the result. Here is the index for the information automatically found.
Google Apps Script can't execute Google Sheets spreadsheet functions like IMPORTXML, so you have two basic alternatives
Use Google Apps Script to get the result of a IMPORTXML formula from the spreadsheet, then use JavaScript to do the rest of the job
Do the job completely using Google Apps Script and JavaScript
Related
Google docs ImportXML called from script
(javascript / google scripts) How to get the title of a page encoded with iso-8859-1 so that the title will display correctly in my utf-8 website?

Google Apps Script (Web Apps): Can I use query strings?

I had this idea to create an Apps Script app that I could pass a Google Drive spreadsheet name and have it return .CSV output. So, basically a CSV exporter.
I feel like I should be able to do something like this:
https://script.google.com/macros/s/AKfycbykY80bhm_ZwbY1-zXY37JJLD8zToZuxup8-eXovJQ/exec?filename=sheet-i-want-to-export-to-csv
And then receive raw .CSV data as a result.
Is this possible? If so, how?
It seems like Web Apps doesn't allow query strings, at least not via the usual ScriptApp.getService().getUrl() method.
Replace the "key" and the "sheet" or it's id #
"https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key="+key+"&exportFormat=csv&gid="+sheet+"&gridlines=0&printtitle=0&size=7&fzr=true&portrait=1&fitw=1"