2

I have a Spreadsheet with some Apps Script functions bound to it.

I also have an Android client using Google Sheets API v4 to interact with that spreadsheet.

Is there a way for the Android client to call/run some function in the Apps Script code?

The reason I need to code to be run on the Apps Script side, and not simply on the Android client, is because I'm sending some email when something happens to the doc, and I would like the email to be sent from the owner account of the spreadsheet, and not from the Android user authenticated via the API.

I know I can trigger functions implicitly like by adding rows to a doc, but is there a way to directly run a specific function?

3 Answers 3

1

Yes. You can make GET and POST requests to Google apps-scripts. from anywhere that can make REST type calls including clients. If you need authentication there is also the apps-script client libraries. I wrote a short script for emailing from a request from one apps-script to another here. But, it would work if you called the emailing script from your client also.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks! that can work, but that'll allow anyone to trigger my functions, any way of allowing only users with access to my Google spreadsheet to trigger this function?
You can include a custom auth token into the mix. Add it either as a parameter in the request, or in the body. When the request arrives at the end point check to see if the custom auth token matches with the one you have stored on a variable in the end point.
1

Deploy your Google Apps Script as Web Apps > reference, by this way you can run function Get(e) or Post(e) and invoke other functions inside one of them with conditions....

Comments

1

You might have gotten the answer to your question. Just in case you have not, below are some points that may help with your development:

1) Create the server side script (i.e., Google Apps Script) function like usual:

function myFunction(inputVar) {
// do something
return returnVar;
}

2) Create a doGet(e) or doPost(e) function like below - can be in the same .gs file with the function in 1) :

function doGet(e) {

    var returnVar = "";
    if (e.parameter.par1 != null) {
        var inputVar = e.parameter.par1;
        returnVar = myFunction(inputVar);
    }

    return HtmlService.createHtmlOutput(returnVar);

}

3) Publish and deploy your project as webapp. Note the deployed URL.

4) From your Android client do HTTP call with the URL as: your_webapp_url?par1="input value"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.