I want to call a custom function I wrote within my Google Apps Script. When I execute a getJSON I suppose it'll automatically run my doGet(e).
My Javascript:
$.getJSON(https://script.google.com/macros/s/[ID]/exec, function(data){
//code here
});
Is there a possible way to call one of my custom functions for example
My Google Apps Script:
function getNumberOfFans(e){
//code here
}
Do I have to add some kind of extra function parameter to my URL?
doGet(e)
function.You can add search string parameters to the URL of the published Wep App.
Here is an example:
The search string is at the end of the URL, after
exec
. You must add a question mark afterexec
and thenname=value
Where
name
andvalue
will be replaced with your choices.Put the event argument (denoted by the letter "e") into the
doGet(e)
function, not the function you want used.The above code is for a GET request. If you want to use a POST request, don't use a search string in the URL. For a POST request, you will send information in the payload. You'll still use
e.parameter
to access the data sent, but whatever is ine.parameter
will be an object with key/value pairs. You'll need to know what the key (property) name is that was sent in the object.For an explanation on URL Parameters, see this documentation:
URL Parameters