Google Apps Script

Class Site

An object representing a Google Site.

Methods

MethodReturn typeBrief description
addEditor(emailAddress)SiteAdds the given user to the list of editors for the Site.
addEditor(user)SiteAdds the given user to the list of editors for the Site.
addEditors(emailAddresses)SiteAdds the given array of users to the list of editors for the Site.
addOwner(email)SiteAdd a new owner to the website
addOwner(user)SiteAdd a new owner to the website
addViewer(emailAddress)SiteAdds the given user to the list of viewers for the Site.
addViewer(user)SiteAdds the given user to the list of viewers for the Site.
addViewers(emailAddresses)SiteAdds the given array of users to the list of viewers for the Site.
createAnnouncementsPage(title, name, html)PageCreate a new AnnouncementsPage.
createFileCabinetPage(title, name, html)PageCreate a new FileCabinetPage.
createListPage(title, name, html, columnNames)PageCreate a new ListPage.
createPageFromTemplate(title, name, template)PageCreate a new page from a template.
createWebPage(title, name, html)PageCreate a new WebPage.
getAllDescendants()Page[]Get the first page of descendant pages.
getAllDescendants(options)Page[]Get all descendant pages of the given type.
getChildByName(name)PageGets a particular child page.
getChildren()Page[]Get the first page of child pages.
getChildren(options)Page[]Get all child pages with optional advanced arguments
getEditors()User[]Gets the list of editors for this Site.
getName()StringReturn the name of the site
getOwners()User[]Retrieves list of owners for the site
getSummary()StringReturn the summary of the web site
getTemplates()Page[]Returns all template pages.
getTheme()StringGets the theme of the site
getTitle()StringReturn the title of the site
getUrl()StringRetrieves the url of this Site.
getViewers()User[]Gets the list of viewers and commenters for this Site.
removeEditor(emailAddress)SiteRemoves the given user from the list of editors for the Site.
removeEditor(user)SiteRemoves the given user from the list of editors for the Site.
removeOwner(email)SiteRemoves owner from the site by user email
removeOwner(user)SiteRemoves owner from the site
removeViewer(emailAddress)SiteRemoves the given user from the list of viewers and commenters for the Site.
removeViewer(user)SiteRemoves the given user from the list of viewers and commenters for the Site.
search(query)Page[]Get all descendant pages matching a search.
search(query, options)Page[]Get all descendant pages matching a search.
setSummary(summary)SiteSet the summary of the web site
setTheme(theme)SiteSets the theme of the site Theme must be a valid theme string.
setTitle(title)SiteSet the title of the site

Detailed documentation

addEditor(emailAddress)

Adds the given user to the list of editors for the Site. If the user was already on the list of viewers, this method promotes the user out of the list of viewers.

Parameters

NameTypeDescription
emailAddressStringthe email address of the user to add

Return

Site — this Site, for chaining


addEditor(user)

Adds the given user to the list of editors for the Site. If the user was already on the list of viewers, this method promotes the user out of the list of viewers.

Parameters

NameTypeDescription
userUsera representation of the user to add

Return

Site — this Site, for chaining


addEditors(emailAddresses)

Adds the given array of users to the list of editors for the Site. If any of the users were already on the list of viewers, this method promotes them out of the list of viewers.

Parameters

NameTypeDescription
emailAddressesString[]an array of email addresses of the users to add

Return

Site — this Site, for chaining


addOwner(email)

Add a new owner to the website

 
var site = SitesApp.getSite("example.com", "mysite");
 site.addOwner("eric@example.com");
 

Parameters

NameTypeDescription
emailStringThe email of the user to add as an owner

Return

Site — this site for chaining


addOwner(user)

Add a new owner to the website

 
var site = SitesApp.getSite("example.com", "mysite");
 var currentUser = Session.getActiveUser();
 site.addOwner(currentUser);
 

Parameters

NameTypeDescription
userUserThe user to add as an owner

Return

Site — this site for chaining


addViewer(emailAddress)

Adds the given user to the list of viewers for the Site. If the user was already on the list of editors, this method has no effect.

Parameters

NameTypeDescription
emailAddressStringthe email address of the user to add

Return

Site — this Site, for chaining


addViewer(user)

Adds the given user to the list of viewers for the Site. If the user was already on the list of editors, this method has no effect.

Parameters

NameTypeDescription
userUsera representation of the user to add

Return

Site — this Site, for chaining


addViewers(emailAddresses)

Adds the given array of users to the list of viewers for the Site. If any of the users were already on the list of editors, this method has no effect for them.

Parameters

NameTypeDescription
emailAddressesString[]an array of email addresses of the users to add

Return

Site — this Site, for chaining


createAnnouncementsPage(title, name, html)

Create a new AnnouncementsPage.

 
// This method can be called from both a Site instance
 // as well as a Page instance
 var site = SitesApp.getSite("example.com", "mysite");
 var page = site.getChildren()[0];

 site.createAnnouncementsPage("New Announcement", 
                              "new-announcement", 
                              "<h1>Your announcement goes here</h1>");

 page.createAnnouncementsPage("New Announcement", 
                              "new-announcement-child", 
                              "<h1>Your announcement goes here</h1>");  
 

Parameters

NameTypeDescription
titleStringthe page title
nameStringthe page name
htmlStringthe page content

Return

Page — The newly created Page


createFileCabinetPage(title, name, html)

Create a new FileCabinetPage.

 
// This method can be called from both a Site instance
 // as well as a Page instance
 var site = SitesApp.getSite("example.com", "mysite");
 var page = site.getChildren()[0];

 site.createFileCabinetPage("New File Cabinet", 
                            "new-file-cabinet", 
                            "<h1>Your HTML here</h1>");

 page.createFileCabinetPage("New File Cabinet", 
                              "new-file-cabinet-child", 
                              "<h1>Your HTML here</h1>");  
 

Parameters

NameTypeDescription
titleStringthe page title
nameStringthe page name
htmlStringthe page content

Return

Page — The newly created Page


createListPage(title, name, html, columnNames)

Create a new ListPage.

 
// This method can be called from both a Site instance
 // as well as a Page instance
 var site = SitesApp.getSite("example.com", "mysite");
 var page = site.getChildren()[0];

 site.createListPage("New List Page", 
                     "new-list-page", 
                     "<h1>Your List Page HTML here</h1>",
                     [ "col1", "col2" ]);

 page.createListPage("New List Page", 
                     "new-list-page-child", 
                     "<h1>Your List Page HTML here</h1>",  
                     [ "col1", "col2" ]);   
 

Parameters

NameTypeDescription
titleStringthe page title
nameStringthe page name
htmlStringthe page content
columnNamesString[]the column names used for the list

Return

Page — The newly created Page


createPageFromTemplate(title, name, template)

Create a new page from a template.

 
var site = SitesApp.getSite("example.com", "mysite");
 var template = site.getTemplates()[0];

 // If an invalid template is passed, this will throw an "Invalid Argument"
 // error
 site.createPageFromTemplate("ClonedPage", "cloned-page", template);
 

Parameters

NameTypeDescription
titleStringthe page title
nameStringthe page name
templatePagethe template page

Return

Page — the newly created Page


createWebPage(title, name, html)

Create a new WebPage.

 
// This method can be called from both a Site instance
 // as well as a Page instance
 var site = SitesApp.getSite("example.com", "mysite");
 var page = site.getChildren()[0];

 site.createAnnouncementsPage("New Announcement", 
                              "new-announcement", 
                              "<h1>Your announcement goes here</h1>");

 page.createAnnouncementsPage("New Announcement", 
                              "new-announcement-child", 
                              "<h1>Your announcement goes here</h1>");  
 

Parameters

NameTypeDescription
titleStringthe page title
nameStringthe page name
htmlStringthe page content

Return

Page — The newly created Page


getAllDescendants()

Get the first page of descendant pages.

 
var site = SitesApp.getSite("example.com", "mysite");
 var pages = site.getAllDescendants();
 

Return

Page[] — an array of direct and indirect child pages


getAllDescendants(options)

Get all descendant pages of the given type.

 
var site = SitesApp.getSite("example.com", "mysite");
 var descendants = site.getAllDescendants({
   type: SitesApp.PageType.WEB_PAGE,
   start: 0,
   max: 25,
   includeDrafts: false,
   includeDeleted: true,
   search: "target"
 });

 for(var i in descendants) {
   Logger.log(descendants[i].getName());
 }
 

Parameters

NameTypeDescription
optionsObjectJavaScript object fields defined in the Advanced Arguments section below

Advanced parameters

NameTypeDescription
typePageType[]only get pages of this type
startIntegerstart the results here
maxIntegerthe max number of results (default 200)
includeDraftsBooleanwhether to include draft pages (default false)
includeDeletedBooleanwhether to include deleted pages (default false)
searchStringonly return pages matching this query

Return

Page[] — an array of direct and indirect child pages of the given type


getChildByName(name)

Gets a particular child page.

 
var site = SitesApp.getSite("example.com", "mysite");
 var pages = site.getChildByName("childPage");
 

Parameters

NameTypeDescription
nameStringthe child page name

Return

Page — the child page


getChildren()

Get the first page of child pages.

 
var site = SitesApp.getSite("example.com", "mysite");
 var pages = site.getChildren();
 

Return

Page[] — an array of direct child pages.


getChildren(options)

Get all child pages with optional advanced arguments

 
var site = SitesApp.getSite("example.com", "mysite");
 var childPages = site.getChildren({
   type: SitesApp.PageType.WEB_PAGE,
   start: 0,
   max: 25,
   includeDrafts: false,
   includeDeleted: true,
   search: "target"
 });

 for(var i in childPages) {
   Logger.log(childPages[i].getName());
 }
 

Parameters

NameTypeDescription
optionsObjectJavaScript object fields defined in the Advanced Arguments section below

Advanced parameters

NameTypeDescription
typePageType[]only get pages of this type
startIntegerstart the results here
maxIntegerthe max number of results (default 200)
includeDraftsBooleanwhether to include draft pages (default false)
includeDeletedBooleanwhether to include deleted pages (default false)
searchStringonly return pages matching this query

Return

Page[] — an array of direct child pages of the given type


getEditors()

Gets the list of editors for this Site. If the user who executes the script does not have edit access to the Site, this method throws an exception.

Return

User[] — an array of users with edit permission


getName()

Return the name of the site

 
var name = SitesApp.getSite('example.com', 'mysite').getName();
 

Return

String — the name of this Site instance


getOwners()

Retrieves list of owners for the site

 
var owners = SitesApp.getSite('example.com', 'mysite').getOwners();
 for(var i in owners) {
   Logger.log(owners[i].getEmail())
 }
 

Return

User[] — an array containing User instances representing owners


getSummary()

Return the summary of the web site

 
var summary = SitesApp.getSite('example.com', 'mysite').getSummary();
 

Return

String — the summary of this site


getTemplates()

Returns all template pages.

 
var templates = SitesApp.getSite('example.com', 'mysite').getTemplates();
 for(var i in templates) {
   Logger.log(templates[i].getName())
 }
 

Return

Page[] — an array containing Page instances representing templates


getTheme()

Gets the theme of the site

 
var theme = SitesApp.getSite('example.com', 'mysite').getTheme();
 

Return

String — the theme of this site


getTitle()

Return the title of the site

 
var title = SitesApp.getSite('example.com', 'mysite').getTitle();
 

Return

String — the title of this site


getUrl()

Retrieves the url of this Site.

 
var url = SitesApp.getSite('example.com', 'mysite').getUrl();
 

Return

String — the url of this Site instance


getViewers()

Gets the list of viewers and commenters for this Site. If the user who executes the script does not have edit access to the Site, this method throws an exception.

Return

User[] — an array of users with view or comment permission


removeEditor(emailAddress)

Removes the given user from the list of editors for the Site. This method does not block users from accessing the Site if they belong to a class of users who have general access — for example, if the Site is shared with the user's entire domain.

Parameters

NameTypeDescription
emailAddressStringthe email address of the user to remove

Return

Site — this Site, for chaining


removeEditor(user)

Removes the given user from the list of editors for the Site. This method does not block users from accessing the Site if they belong to a class of users who have general access — for example, if the Site is shared with the user's entire domain.

Parameters

NameTypeDescription
userUsera representation of the user to remove

Return

Site — this Site, for chaining


removeOwner(email)

Removes owner from the site by user email

 
// This snippet removes the user with the given email from the owners list
 var site = SitesApp.getSite('example.com', 'mysite');
 site.removeOwner("eric@example.com");
 

Parameters

NameTypeDescription
emailStringThe email of the user to remove from the owners

Return

Site — the site instance for method chaining


removeOwner(user)

Removes owner from the site

 
// This snippet removes the current user from the list of owners
 var site = SitesApp.getSite('example.com', 'mysite');
 site.removeOwner(Session.getActiveUser());
 

Parameters

NameTypeDescription
userUserA user to remove from the list of owners

Return

Site — the site instance for method chaining


removeViewer(emailAddress)

Removes the given user from the list of viewers and commenters for the Site. This method has no effect if the user is an editor, not a viewer or commenter. This method also does not block users from accessing the Site if they belong to a class of users who have general access — for example, if the Site is shared with the user's entire domain.

Parameters

NameTypeDescription
emailAddressStringthe email address of the user to remove

Return

Site — this Site for chaining


removeViewer(user)

Removes the given user from the list of viewers and commenters for the Site. This method has no effect if the user is an editor, not a viewer. This method also does not block users from accessing the Site if they belong to a class of users who have general access — for example, if the Site is shared with the user's entire domain.

Parameters

NameTypeDescription
userUsera representation of the user to remove

Return

Site — this Site for chaining


search(query)

Get all descendant pages matching a search.

 
var site = SitesApp.getSite("example.com", "mysite");
 var matches = site.search("targetText");

 for(var i in matches) {
   Logger.log(matches[i].getName());
 }
 

Parameters

NameTypeDescription
queryStringthe full text search query to match

Return

Page[] — an array of direct and indirect child pages of the given type


search(query, options)

Get all descendant pages matching a search.

 
var site = SitesApp.getSite("example.com", "mysite");
 var childPages = site.getChildren({
   type: SitesApp.PageType.WEB_PAGE,
   start: 0,
   max: 25,
   includeDrafts: false,
   includeDeleted: true,
   search: "target"
 });

 for(var i in childPages) {
   Logger.log(childPages[i].getName());
 }
 

Parameters

NameTypeDescription
queryStringthe full text search query to match
optionsObjectJavaScript object fields defined in the Advanced Arguments section below

Advanced parameters

NameTypeDescription
typePageType[]only get pages of this type
startIntegerstart the results here
maxIntegerthe max number of results (default 200)
includeDraftsBooleanwhether to include draft pages (default false)
includeDeletedBooleanwhether to include deleted pages (default false)

Return

Page[] — an array of direct and indirect child pages of the given type


setSummary(summary)

Set the summary of the web site

 
var site = SitesApp.getSite("example.com", "mysite");
 // All of the setter methods return the site instance so setters
 // can be chained
 site.setTitle("My Site")
     .setSummary("This is my site")
     .setTheme("simple");
 

Parameters

NameTypeDescription
summaryStringA string summary describing the site

Return

Site — the site for method chaining


setTheme(theme)

Sets the theme of the site Theme must be a valid theme string. For an exhaustive list, write a test method and pass an invalid value to setTheme(). The script will throw a Service error and return an exhaustive list of available themes. The list of available themes is also available under Manage Site->Themes. Theme name strings are generally the same as the theme name on the Themes page in lower cases with spaces and special characters removed. For example, the string for "Terra: Water" would be "terrawater".

 
var site = SitesApp.getSite("example.com", "mysite");
 // All of the setter methods return the site instance so setters
 // can be chained
 site.setTitle("My Site")
     .setSummary("This is my site")
     .setTheme("simple");
 

Parameters

NameTypeDescription
themeStringa string name for the theme to set for this Site

Return

Site — the site for method chaining


setTitle(title)

Set the title of the site

 
var site = SitesApp.getSite("example.com", "mysite");
 // All of the setter methods return the site instance so setters
 // can be chained
 site.setTitle("My Site")
     .setSummary("This is my site")
     .setTheme("simple");
 

Parameters

NameTypeDescription
titleStringthe new title of the site

Return

Site — the site for method chaining

Deprecated methods





















Authentication required

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

Signing you in...

Google Developers needs your permission to do that.