How to make Google App script triggers to run on script executions or API requests? - google-apps-script

I am aware that installable triggers do not execute/run on Script executions or updates via API requests. For triggers to run, the change or edit has to be done 'manually'. Is there any work-around or solution to this?
Here is my usecase:
I have designed HTML UI that accepts some data and stores that in specific spreadsheet
Since I didn't want any users to have access to backend spreadsheet (to restrict view to other's submission), I have created REST service using TIBCO Cloud Integration > Google connector that writes data to Google spreadsheet
When user submit the response, UI internally invokes above-mentioned TIBCO API and that in turn updates the spreadsheet (using my Google credentials) with response submitted by user
With this arrangement, I don't have to share my Google spreadsheet with all users and expose all submissions. I could have used Google Form, but that is too basic and my UI requirements are quite complex.
Until this point, everything works fine, but as a part of some advance features, I want some functions (written in the script of backend spreadsheet) to trigger on 'onEdit' when my API call write to the spreadsheet and that is where I am stuck. So far, I have tried:
Exposing Google Script as an REST API
Exposing Google Script as Library function
but in all cases, I have to share the spreadsheet with user that invokes the calls, and I dont want that, thanks.

Related

How to use Google ApiClient to pull Google Form and the responses (PHP)

Im use this Google ApiClient https://developers.google.cn/apps-script/api/quickstart/php
To pull Form & Responses, but same the api just add script to script.google
Please show me example to get the list form and Responses
Thanks
As of this writing there are no explicit REST APIs to pull Google Form data, so you won't be able to pull form responses directly from the Google API PHP client.
It you want to access form responses from PHP you'll need to use App Script to create a custom intermediary service/API that exposes the information you want.
You're already aware of the Apps Script API, so you can try creating a series of custom Apps Script functions to pull form responses and then call the Apps Script API from PHP to execute those functions to return the requisite data.
None of this is trivial to implement, and I don't have any code that I can share. But I'd start with reading the Apps Script API documentation and work out a solution from there.

Authorizing Google Charts to access private spreadsheets

I am trying to create a Web App using Google Apps Script to query data from my Google Sheet using Google Charts.
I have been able to successfully query the spreadsheet when the Google Sheet is publicly shared, however since the spreadsheet contains confidential info I would rather do it privately using authorizations.
The reason why I want to use Google Charts visualisation functions (as opposed to the server side Spreadsheet App) is because of the speed of querying large data sets.
I have tried following the steps in the above documentation. That is, creating a client id then using the gapi.auth library to authenticate myself but I continue to receive an error.
When i add the authorization library and first part of the code from the documentation (with console.log simply to see where it get's up to):
<script src="https://apis.google.com/js/auth.js?onload=init"></script>
<script>
var clientId = '1234.apps.googleusercontent.com';
var scopes = 'https://spreadsheets.google.com/feeds';
function init() {
console.log("here");
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true},handleAuthResult);
}
</script>
I receive the following error:
1289869776-mae_html_user_bin_i18n_mae_html_user.js:41 dropping
postMessage.. was from unexpected window
Any guidance is appreciated.
Since you are creating your web app using Google Apps Script, it's not necessary to "authorize Google Charts to access private charts" because you could use Google Apps Script services and methods to get the data from the spreadsheets and pass them to Google Charts.
On Converting from UiApp + Chart Service to Html Service + Google Visualization API it's shown how to convert the old dashboard example from from UiApp + Chart Service to HtmlService + Google Visualization API. This illustrates how to create a Google Apps Script web app that builds a chart from Google Spreadsheet data without "requiring authorization" as it's "implicitly" handled by Google Apps Script.
From the above link
Two functions cooperate to retrieve the dashboard’s data and display it. As soon as the visualization API is loaded, the sendQuery() function is invoked. Using the google.script.run facility, it sends its request to the server-side getSpreadsheetData() function. This is an asynchronous operation, so two callbacks are provided, a successHandler and a failureHandler. One or the other will receive the result of the server call, depending on the outcome.
H/T to jfllmartin, author of an answer to Converting my google dashboard app from the UI service to the HTML service where the above link was shared.
Related
How to create google dashboard including piechart and range select filter from a spreadsheet?
Display Spreadsheet data in Sites with Html Service
can I suggest you change from using Google sheets to using firebase with Google sheets or just Firebase, and then with Google appscript in the back end.
I often use a Google script to problematically update Firebase with data from the Google sheet. I then enjoy the speed and security of Firebase to deliver a super fast user experience.
There are two go to pages for using Firebase in appscript. The example page and the quick start.
Furthermore, I gave up using Google's own charting library and starting using high charts or chartJS, as they are more accessible.

Crud Webapp Google Apps Script

Is it possible create Crud Webapp with Google Apps Script. I need to create a web table able to update and get values from Google spreadsheet?
yes its possible, you can insert, update a row, delete and retreive a row using google app scripts
try this link https://github.com/AishwaryT/Google-app-script-crud
let me know if you face any problem.
Yes absolutely it is possible.
Write a code in Google app script for CRUD operation over the Google spreadsheet (like Insert, Update, delete). accept the parameters using doGet() / doPost() method to insert/update data into the Google spreadsheet and return the updated data or any response in the JSON/XML or in the string format, deploy your app script (with "anyone even anonymous"), copy the URL of the deployed script and call to that URL from your your web application (in java script AJAX call) and get response from app script to your application.
Reference :https://developers.google.com/apps-script/

Call Google Spreadsheet script function from external app

I have Google spreadsheet with script attached to it (with the Tools->Script Editor tool).
I want to call one of script function from external Android App. Is it possible? Should I use Spreadsheet API?
Unfortunately, you cannot directly call your script from any external application.
However, you can change it to be a web application, then invoke it via an HTTP GET or POST from almost anywhere, including an Android app.
Insert new rows into Google Spreadsheet via cURL/PHP - HOW? provides an example of a web app that you could adapt.
Should I use Spreadsheet API?
Your question doesn't actually say what it is you want to do, so the answer is "it depends". You still won't be able to invoke an embedded script using the Spreadsheet API, but you will be able to read and write spreadsheet content.
Obviously the answer depends on your usecases, but have you checked the Google Appscript API?
As stated it
provides methods to remotely execute Apps Script functions

Make a Google web app that's triggered from a Google Spreadsheet form?

I have a Google Apps script (written in a Google Spreadsheet) that creates a separate calendar and events for it with respect to a university course and the university calendar. The GUI is a Spreadsheet form, which triggers the execution of my script. The script gets its input from the spreadsheet form entry.
The trouble I have is that I can't easily deploy my solution to other users. Yes, they can make a copy of my sheet/form/scripts, so that they can run it on their account. Several problems, however, result from this approach:
triggers don't get copied - this is because authorization to access local info (calendars, contacts, etc.) must be given by the users before a trigger is enabled. So users have to re-connect the form submission trigger to the Apps Script for it to work (this is not user friendly).
if I change the code of my apps script, the users are using a copy and won't see the changes.
The solution seems to be Google Web Apps, but from what I've read, I can't re-use the form-based GUI of my approach. Or can I?
Google Spreadsheet Forms have the advantage that they are very easy to create, and you can already specify what fields are mandatory, etc. I don't want to have to re-write all of this in a complicated GUI front-end to my Google Apps Script (Edit: even the GUI builder tool seems way more complicated than a Spreadsheet Form), yet I want other users to be able to create the calendars and events in their own Google accounts. Is there a way to keep my form, but have it hooked to a Web App version of my code?
Try adding the form on a google sites (intranet). This way, any user having access, will be able to use the form as it is. All logic you created will remain the same.
Creating a script however will allow the user to execute the script "under their login", thus enabling access to calendars, contacts......