Possible to call Apps Script functions from other platforms? - google-apps-script

I've written some functions in Google's apps script; both return strings of text and require one parameter
Is it possible to call these functions from an entirely different platform?
Specifically, I'm wanting to call function(parameter) when a script I've got set up on an IRC network is triggered.
I was hoping there was some way to do this though HTTP by deploying the code as an app but I'm not sure where to start or if it's even possible
Any help would be appreciated!

Check out the ContentService samples here.

Related

Apps Script: GmailApp not defined

I'm trying to create a Google Apps Script to delete some email in bulk. The code for this doesn't really matter though as the GMailApp object isn't defined. I create a new project, add the following code:
function main() {
var threads = GMailApp.search('.....');
}
and I just get an error 'ReferenceError: GMailApp is not defined'. Do I have to enable the GMailApp? I thought the point of the app services was that they didn't need an API to be enabled, and that they can just be linked and used.
Any help appreciated,
Thanks
From menu select "Resources" -- "Advanced Google Services" and turn "Gmail API" on.
Pay attention to write in code GmailApp, not GMailApp.
It's easy to avoid typos by getting used to using the "Control-Spacebar" short cut.
When you are in the Apps Script IDE holding control and spacebar at the same time will give you a popup of all the classes and then you just select the one you want.
So in summary, the API object is GmailAPP, not GMailApp. The autocomplete with ctrl+space should help with problems like these however at some point I had it autocompleting my code so it must have got confused down the line. Thank you for your answers.
2021 Update for the Gmail API (not GmailApp)
If you're in the 2021 and later IDE, it's here:
Also, note that Gmail is different from GmailApp. In my experience Gmail is more customizable, because you're getting exposed to the Gmail API whereas GmailApp is a less-robust collection of methods, but it's simpler to use.

How to invoke Python script from google apps script

I have a small Google apps script which is invoked with an onClick event to retrieve the last row added. Next step is I need the apps script to invoke a python script internally. Is there a way to do that?
I am new to Apps script so any help is appreciated. Thank you in advance
Google Apps Script is quite similar to JavaScript itself. So, can you execute python inside JS code. I guess no.
A way that I can think of exposing that python code via Ajax Call. You can invoke the URL from the Apps Script. REST APIs come in handy to break the boundaries of languages.
But yeah, in this approach you do need to host an API. I do that using Google Cloud Functions which are really brilliant where building an API in python/nodejs is quick and easy(few minutes) with a ready HTTPS URL.

Custom formula returning #NAME when Google Sheets is published to web

I'm not much of a programmer, but I managed to write a Google Sheets script that sorts an array, filters out specified values, and returns the new array. It works great.
However, when I publish the output page to the web, the link will only successfully show the output if I have the back end sheet open. As soon as I close it, the publish page turns up #NAME.
Presumably there is some restriction as to the availability of custom scripts. I assumed the output would just grab the text, but I suppose it's trying to run it and can't without someone being logged in?
Anyways - is there some way around this?
Thanks
Edit: Did a little further reading and found out that this might be a situation where "script as web app" might be the requirement. As a novice, this is a little over my head and I'd appreciate any advice.
I also tested to make sure IMPORTRANGE() as a source for this data wasn't the issue, and though it may cause other problems once I get the #name issue resolved, it does not appear to be at fault here specifically since the same thing happens with local data.
Yes, as you've stated, script as web app might be the requirement. You may also want to check this documentation regarding Custom Functions in Google Sheets. Just be noted that a script can be published as a web app if it meets these requirements:
It contains a doGet(e) or doPost(e) function.
The function returns an HTML service HtmlOutput object or a Content service TextOutput object.
Hope this helps!

Debugging GScript called by Google App

I have written some GScript that is called by a Google App (Awesome Tables).
How do I debug the GScript while it is running after being initiated by the Google App (I particularly want to see that values in variables as I step through the code)?
I found that Google Apps Script has a Logger Class. I used this to log messages when certain stages in my code was reached (some included variable values) and then emailed the whole log to myself. See https://developers.google.com/apps-script/reference/base/logger
I don't know of a way to do this. The best approach is probably to mimic the calling application by creating a test function in your Google Apps Script that calls the main function with the appropriate parameters. Then you can step through the code and see values using the debugger.
Try to check this Debugging part in the Google Apps Script documentation if it can help you.
It is stated here that there are some strategies for handling errors and investigating a script that is not running the way you expect.
Execution transcript
Logging custom messages
Using the debugger and breakpoints
For more information, check this Some Simple Debugging for Google Apps Script

Invoking apps script within another apps script

Is there any way to invoke a Google Apps Script which serves content and limited to a domain within another Google Apps Script which is invoked by a user who is in that domain? Basically the content serve script is something which runs on administrator of the domain and serves private information.
I think it should work when content serving script is made, available to anonymous usage, but I wanted the content serving script to be available only within domain.
You could publish the first script as a web service, and then just call the functions remotely.
This can be done because when you publish as a web application you set the permissions with which the script gets executed.
https://developers.google.com/apps-script/execution_web_apps
Unfortunately, this isn't possible, as the script request aren't executed in the name of the author neither the user executing it, setting anonymous usage for the script should work.
But you can pass an argument through post or get. so even if anyone can invoke the script, only the script invoked with a key argument will do something
The question that remain is what to use: get or post
I don't know if request made by the script are done in https, so it's maybe a better solution to use post.
is a library what you're looking for? Remember this may slow down executions (vs just binding the script to multiple files like normal)
https://support.google.com/docs/thread/13371261?hl=en
Yes, it is possible. The simplest solution is to create an Apps Script library. You can use either a standalone script or a bound script as the library. I prefer to use a standalone to make it easier to access, and you won't be able to use functions that are specific to bound scripts that could mess up your script.
HERE is a quick video demonstrating how to get a GAS library setup.
https://www.youtube.com/watch?v=TqWtSp4IJcg&feature=youtu.be