Google Apps Script

Class Service

Access and manipulate script publishing.

Properties

PropertyTypeDescription
RestrictionService.RestrictionEnum representing the access restrictions on a script exported as a service.

Methods

MethodReturn typeBrief description
disable()voidDisable the script as being accessed as a service.
enable(restriction)voidEnable the script to be accessed as a web app with the specified permissions This will enable the service to be accessible as a service.
getUrl()StringReturns the URL of the published service, otherwise returns null.
isEnabled()BooleanReturns true if the script is accessable as a service.

Detailed documentation

disable()

Disable the script as being accessed as a service. Disables the service from being accessible via the service url. This functionality is the same as if you went to the "Publish" > "Deploy as web app" dialog and unchecked the "enable service" checkbox.

 
// Disable the script from being available at it's service url
 ScriptApp.getService().disable();
 

enable(restriction)

Enable the script to be accessed as a web app with the specified permissions This will enable the service to be accessible as a service. This functionality is as if you went to the "Publish" > "Deploy as web app" dialog and checked the "enable service" checkbox. You can either share to yourself with Restriction.MYSELF, share to the domain with Restriction.DOMAIN, or share to everyone with Restriction.ALL. Not all sharing modes are valid in all domains. The url for the published service can be obtained by calling ScriptApp.getService().getUrl(). Note: this function will only work on the execution directly following the appearance of the authorization dialog. This uses the one-shot authorization functionality so that if you want to call this on a subsequent execution, you'll have to invalidate the scripts authorization by calling ScriptApp.invalidateAuth(), have the user re-run the script so they will click through the authorization panel, and then run it again to have this function enabled, otherwise this function will throw an error. Note that the script must have at least one version saved before this function will work.

 
var service = ScriptApp.getService();
 service.enable(service.Restriction.ALL);
 // Other options are:
 //    Restriction.DOMAIN
 //    Restriction.MYSELF

Parameters

NameTypeDescription
restrictionService.Restrictionwho is allowed to access the service as published via the service url

getUrl()

Returns the URL of the published service, otherwise returns null.

 
// mail myself a message as to the url of my published as service script
 MailApp.sendMail("myself@example.com", "My Snazzy App",
   "My new app is now available at " + ScriptApp.getService().getUrl());
 

Return

String — the url of the published service


isEnabled()

Returns true if the script is accessable as a service.

 
var svc = ScriptApp.getService();
 if (!svc.isEnabled()) 
{   *   // it's not enabled, and should be
   svc.enable(svc.Restriction.MYSELF);
 }
 

Return

Boolean — true if the script is published as a service, false otherwise

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.