I'm trying to develop a simple web app using google script web app service and access it from another script using the UrlFetch service.
My problem is that in order to try the code on my web app I have to publish a new version every time because trying to access to the dev URL returns returns and HTML file telling me to sign in even though I've set the permissions for the web app to everyone, including anonymous (if I hit the production URL it does work, though).
I'm assuming that Google is limiting the access to the dev URL for security reasons but can someone shed a light on that assumption?
PS: I don't know if this is relevant but my google account is in a Google Apps for Education domain
Edit
I've found a method to avoid publishing the application for each code change: instead of calling it from the UrlFetch service, I've created a function in the web App code that does call the doPost or the doGet method (I've to create the request param, but that's easy) and I've changed the end of the script to log the result insted of returing it to the client. When the application will be ready, I can publish and develop the client using the UrlFetch.
Anyhow, if anyone knows about the limitation of the dev URL that would be great!
your assumption is correct, the dev url ignores your publishing permissions on purpose, only the developer has access to that url.
you could accomplish what you want using libraries. move the code in your called script to a library and add it to that script as "development mode" and publish your script service.
changing library code should also change your service because its on development mode.
Note that this can easily break your app if you save partial code changes, and makes it hard to test your changed code unless you make all changes and tests in a separate script copy. Making several changes at once in multiple apps script editor files is possible with their "Save all" File menu command (after manually pasting all code changes from your tested copy).
Related
I have written an Apps Script for personal use that I want to invoke with an HTTP request. (I'm basically using this like a "serverless function" with native authentication to Google Apps APIs.)
I can do this easily by deploying my Apps Script project as a Web App, which gets me a URL like
https://script.google.com/macros/s/${DEPLOYMENT_ID}/exec
However, if I make changes to my script and want to push those changes live, I have to create a new deployment, which will have a new deployment ID, thus changing the URL.
I know that I could use a "Test Deployment" to get a URL that always points to the project HEAD, but this always requires authentication from the HTTP client. With my deployment, I can set "Who has access" to "Anyone" and avoid this requirement.
Is it possible to deploy a web app script to a URL that will not change on future deployments?
In the old editor deploying to the same URL is the default behavior because you can only have one deployment. The new editor allows you to have multiple deployments, each with its own URL and (possibly) pointing to different versions of your application.
To update an existing deployment to a different version, or to create a new version, you need to edit your deployment's configuration.
Editing deployment configuration
I have a project in GCP with some internal APIs (in VMs), Databases, and so on.
Now, I'm trying to create a GAS to obtain data from one of those internal APIs (Druid, in my case) to print some data in a Google Spreadsheet.
My point here is that I link the GAS to my GCP project, expecting to be able to connect to my internal IP (10.1.0.x) which is in a VPC, shared with the default one. So, if I start a new VM attached to the default network, I could be able to ping and connect to it. Seems reasonable.
But, when I execute the GAS function, the following pice of code fails: UrlFetchApp.fetch('http://10.1.0.3:8082/druid/v2/?pretty', options);.
Should I configure something else in the GCP project to be able to connect to internal APIs?
Should I change the way and use another GCP service to do so?
Any help would be more than appreciated!
Thanks
That is not supported in Apps Script. You could request a feature request in the bug tracker. See https://developers.google.com/apps-script/support#missing_features
Internal APIs run client-side and need to be incorporated within JavaScript code.
Within Apps Script you can run JavaScript code, if you deploy your project as a Web App.
You can then either embed the JS code within the HTML file attached to the project, or directly insert it within the <script></script> tags within HtmlService.createHtmlOutput().
How can I find a Google App Script web app I deployed and modify it? It does not appear in my drive. Perhaps I didn't save it. Does it persist or disappear eventually? Is there somewhere that list all deployed web apps? If so, I have been unable to find it.
If your webapp is recent, simply replace "exec" at the end of the url with "edit" (without quotes) and you'll get the script editor opened on your script.
(Very old webapp have a different structure but it changed quite a long time ago so I guess you're not concerned with that.)
No. There is nothing like deployed webapps list. if u didn't save, u can't get it back even though you had deployed it. Make a try to open that script with the url available in your browser's history.
I am developing a one of those bulk delete script for gmail. I want to create a front end for the script so I can easily modify my settings on a per-label basis to specify how many emails I want to delete during a trigger event and how old they have to be for a particular label. I want to be able to test the interface similar to testing a script.....just hit the run button. However, google's script engine tells me I need to deploy the script and it's HTML files as a web app to test the interface.
Is there anyway to test the the interface and its interaction with my backend google script without deploying as a web app?
The answer is no, unless you "deploy" your code through a Spreadsheet. In fact, it's fairly well-documented.
See Serve HTML as a Google Docs, Sheets, or Forms user interface on that page for a "workaround" to testing your app without actually deploying it.
However, there is no harm in deploying it as a webapp. And as a matter of fact, you can see changes instantly after refreshing your app that you have deployed (published), using the dev macro you're given when you deploy it. This is the most useful tool for UiApp and HTMLService:
Edit: After you're done testing and you've "finalized" your code, you can disable the webapp, meaning that nobody can accidentally access it, you don't post the macro link to it, etc. It's a one-click process. Again, this is really the only way to test the code in my opinion, as it's most succinct for a real "development process". See image below:
I would like to make a copy of a Google Spreadsheet file between users that are not on the same domain. The source file has a sharing setting of Anyone with the link can edit.
I created a Web App (with execution permissions set to User accessing the web app) that call an install function:
I was hoping the code would read the source file which is open to everybody and make a local copy to the Google Drive of the user running the Web App (of course assuming the user accept to run the script). The behavior works when it's me running it (because I am the owner of the source) but do not work if the user is from another domain.
Any suggestions on how to achieve this?
function doInstall() {
// The source file is readable by everybody with the link;
var file = DocsList.getFileById('0AlVPTKz1xoevdHc1ZTQ2OGFMXXXXXXXYYYYZZZZ');
file.makeCopy('Test Copy Spreadsheet');
}
I had a different but similar use case and problem. Like you, my source file was accessible to anyone with the link and my domain settings allowed users to share content outside my domain. It worked for me but not for them.
This might work for you, it has for me (so far):
Assuming you have your original script...
Create a separate script for 'Script as web app'.
Write a function (e.g. loadFileIds()) to store the necessary fileIds using ScriptDb. Run the loadFileIds() function.
Write another function (e.g. getFileId()) in the same project that returns your desired file Id from ScriptDb.getMyDb when called. Avoid using DocsList in this function. I originally thought that because getFileId() would 'run as me' that it would be OK but it was always the DocsList line that caused failures when other users triggered the script.
In File > Manage Versions: Save a version of the project.
Under Publish: Deploy that version of your project as a web app. Choose Execute the app as "me(me#mydomain.com)" and set Who has access to the web app to "Anyone".
In your original project go to Manage Resources and enter the Project Key of the web app, choose a version and copy the identifier.
Write a function that calls yourIdentifier.getFileId() and - hopefully - returns the fileId.
In my experience so far external users have been able to access files that they could not when DocsList methods returned null. But there is one more thing to add... You might find you have to share your web app script with your users. I haven't quite made certain that's necessary but I've encountered bugs when I don't. I untick the option to email them the link.
I learned how to do this from examples in the documentation, this video and of course StackOverflow.
As you can see, I'm still working this out myself and testing of the system has so far been just me simulating other users. So no promises. Good luck! I'll star your issue.