Class Site - Google Apps Script � Google Developers
Site
An object representing a Google Site.
Methods
Method
Return type
Brief description
addEditor(emailAddress)
Site
Adds the given user to the list of editors for the Site.
addEditor(user)
Site
Adds the given user to the list of editors for the Site.
addEditors(emailAddresses)
Site
Adds the given array of users to the list of editors for the Site.
addOwner(email)
Site
Add a new owner to the website
addOwner(user)
Site
Add a new owner to the website
addViewer(emailAddress)
Site
Adds the given user to the list of viewers for the Site.
addViewer(user)
Site
Adds the given user to the list of viewers for the Site.
addViewers(emailAddresses)
Site
Adds the given array of users to the list of viewers for the Site.
createAnnouncementsPage(title, name, html)
Page
Create a new announcements page.
createFileCabinetPage(title, name, html)
Page
Create a new file-cabinet page.
createListPage(title, name, html, columnNames)
Page
Create a new list page.
createPageFromTemplate(title, name, template)
Page
Create a new page from a template.
createWebPage(title, name, html)
Page
Create a new web page.
getAllDescendants()
Page[]
Gets an array of descendant pages (direct and indirect), up to a limit of 200 pages.
getAllDescendants(options)
Page[]
Gets an array of descendant pages, with optional advanced arguments.
getChildByName(name)
Page
Gets a particular child page.
getChildren()
Page[]
Gets an array of child pages, up to a limit of 200 pages.
getChildren(options)
Page[]
Gets an array of child pages, with optional advanced arguments.
getEditors()
User[]
Gets the list of editors for this Site.
getName()
String
Return the name of the site
getOwners()
User[]
Retrieves list of owners for the site
getSummary()
String
Return the summary of the web site
getTemplates()
Page[]
Returns all template pages.
getTheme()
String
Gets the theme of the site
getTitle()
String
Return the title of the site
getUrl()
String
Retrieves the url of this Site.
getViewers()
User[]
Gets the list of viewers and commenters for this Site.
removeEditor(emailAddress)
Site
Removes the given user from the list of editors for the Site.
removeEditor(user)
Site
Removes the given user from the list of editors for the Site.
removeOwner(email)
Site
Removes owner from the site by user email
removeOwner(user)
Site
Removes owner from the site
removeViewer(emailAddress)
Site
Removes the given user from the list of viewers and commenters for the Site.
removeViewer(user)
Site
Removes the given user from the list of viewers and commenters for the Site.
search(query)
Page[]
Gets an array of descendant pages that match a search query, up to a limit of 200 pages.
search(query, options)
Page[]
Gets an array of descendant pages that match a search query, with optional advanced arguments.
setSummary(summary)
Site
Set the summary of the web site
setTheme(theme)
Site
Sets the theme of the site Theme must be a valid theme string.
setTitle(title)
Site
Set the title of the site
Deprecated methods
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
Name
Type
Description
emailAddress
String
the 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
Name
Type
Description
user
User
a 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 thelist of viewers, this method promotes them out of the list of viewers.
Parameters
Name
Type
Description
emailAddresses
String[]
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("[email protected]");
Parameters
Name
Type
Description
String
The 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
Name
Type
Description
user
User
The 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
Name
Type
Description
emailAddress
String
the 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
Name
Type
Description
user
User
a 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 onthe list of editors, this method has no effect for them.
Parameters
Name
Type
Description
emailAddresses
String[]
an array of email addresses of the users to add
Return
Site -- this Site, for chaining
createAnnouncementsPage(title, name, html)
Create a new announcements page. Note that a parent site or page cannot have more than 500 childpages.
// 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
Name
Type
Description
title
String
the page title
name
String
the page name
html
String
the page content
Return
Page -- the newly created Page
createFileCabinetPage(title, name, html)
Create a new file-cabinet page. Note that a parent site or page cannot have more than 500 childpages.
// This method can be called from either a site or a page.
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
Name
Type
Description
title
String
the page title
name
String
the page name
html
String
the page content
Return
Page -- The newly created Page
createListPage(title, name, html, columnNames)
Create a new list page. Note that a parent site or page cannot have more than 500 child pages.
// This method can be called from either a site or a page.
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
Name
Type
Description
title
String
the page title
name
String
the page name
html
String
the page content
columnNames
String[]
the column names used for the list
Return
Page -- The newly created Page
createPageFromTemplate(title, name, template)
Create a new page from a template. Note that a parent site or page cannot have more than 500 childpages.
// This method can be called from either a site or a page.
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
Name
Type
Description
title
String
the page title
name
String
the page name
template
Page
the template page
Return
Page -- the newly created Page
createWebPage(title, name, html)
Create a new web page. Note that a parent site or page cannot have more than 500 child pages.
// This method can be called from either a site or a page.
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
Name
Type
Description
title
String
the page title
name
String
the page name
html
String
the page content
Return
Page -- The newly created Page
getAllDescendants()
Gets an array of descendant pages (direct and indirect), up to a limit of 200 pages.
var site = SitesApp.getSite("example.com", "mysite");
var pages = site.getAllDescendants();
Return
Page[] -- an array of direct and indirect child pages
getAllDescendants(options)
Gets an array of descendant pages, with optional advanced arguments.
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
Name
Type
Description
options
Object
JavaScript object fields defined in the Advanced Arguments section below
Advanced parameters
Name
Type
Description
type
PageType[]
only get pages of this type
start
Integer
start the results here
max
Integer
the max number of results (default 200)
includeDrafts
Boolean
whether to include draft pages (default false)
includeDeleted
Boolean
whether to include deleted pages (default false)
search
String
only 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
Name
Type
Description
name
String
the child page name
Return
Page -- the child page
getChildren()
Gets an array of child pages, up to a limit of 200 pages.
var site = SitesApp.getSite("example.com", "mysite");
var pages = site.getChildren();
Return
Page[] -- an array of direct child pages
getChildren(options)
Gets an array of 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
Name
Type
Description
options
Object
JavaScript object fields defined in the Advanced Arguments section below
Advanced parameters
Name
Type
Description
type
PageType[]
only get pages of this type
start
Integer
start the results here
max
Integer
the max number of results (default 200)
includeDrafts
Boolean
whether to include draft pages (default false)
includeDeleted
Boolean
whether to include deleted pages (default false)
search
String
only 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 tothe 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 nothave 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 fromaccessing 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
Name
Type
Description
emailAddress
String
the 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 fromaccessing the Site if they belong to a class of users who have general access -- for example, if theSite is shared with the user's entire domain.
Parameters
Name
Type
Description
user
User
a 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("[email protected]");
Parameters
Name
Type
Description
String
The 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
Name
Type
Description
user
User
A 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 usersfrom accessing the Site if they belong to a class of users who have general access -- for example, ifthe Site is shared with the user's entire domain.
Parameters
Name
Type
Description
emailAddress
String
the 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 noeffect if the user is an editor, not a viewer. This method also does not block users from accessing theSite if they belong to a class of users who have general access -- for example, if the Site is sharedwith the user's entire domain.
Parameters
Name
Type
Description
user
User
a representation of the user to remove
Return
Site -- this Site for chaining
search(query)
Gets an array of descendant pages that match a search query, up to a limit of 200 pages.
var site = SitesApp.getSite("example.com", "mysite");
var matches = site.search("targetText");
for(var i in matches)
Logger.log(matches[i].getName());
Parameters
Name
Type
Description
query
String
the full text search query to match
Return
Page[] -- an array of direct and indirect child pages of the given type
search(query, options)
Gets an array of descendant pages that match a search query, 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
Name
Type
Description
query
String
the full text search query to match
options
Object
JavaScript object fields defined in the Advanced Arguments section below
Advanced parameters
Name
Type
Description
type
PageType[]
only get pages of this type
start
Integer
start the results here
max
Integer
the max number of results (default 200)
includeDrafts
Boolean
whether to include draft pages (default false)
includeDeleted
Boolean
whether 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
Name
Type
Description
summary
String
A 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 testmethod and pass an invalid value to setTheme(). The script will throw a Service error and return anexhaustive 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 inlower 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
Name
Type
Description
theme
String
a 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
Name
Type
Description
title
String
the new title of the site
Return
Site -- the site for method chaining
Deprecated methods
addCollaborator(email)
Deprecated. This function is deprecated and should not be used in new scripts.
Add a new collaborator to the site
var site = SitesApp.getSite("example.com", "mysite");
site.addCollaborator("[email protected]");
Parameters
Name
Type
Description
String
The email of the user to add as a collaborator
Return
Site -- this site for chaining
addCollaborator(user)
Deprecated. This function is deprecated and should not be used in new scripts.
Add a new collaborator to the website
var site = SitesApp.getSite("example.com", "mysite");
var currentUser = Session.getActiveUser();
site.addCollaborator(currentUser);
Parameters
Name
Type
Description
user
User
The user to add as a collaborator
Return
Site -- this site for chaining
createAnnouncement(title, html, parent)
Deprecated. This function is deprecated and should not be used in new scripts.
Create a new Announcement
Parameters
Name
Type
Description
title
String
The title of the Announcement page to create
html
String
The HTML body of the page
parent
Page
The Parent page
Return
Page -- The created Page
createComment(inReplyTo, html, parent)
Deprecated. This function is deprecated and should not be used in new scripts.
Deprecated. Replaced with createComment on Page. Create a new Comment.
Parameters
Name
Type
Description
inReplyTo
String
a GData feed url - meaningless and broken
html
String
the comment content
parent
Page
the parent the comments shows up on
Return
Comment -- the newly created Comment
createListItem(html, columnNames, values, parent)
Deprecated. This function is deprecated and should not be used in new scripts.
Deprecated. Replaced by createListItem on Page. Create a new ListItem.
Parameters
Name
Type
Description
html
String
the item content - meaningless and broken.
columnNames
String[]
the names of the columns, which are unnecessary
values
String[]
the column values
parent
Page
the ListPage parent
Return
ListItem -- the ListItem for chaining.
createWebAttachment(title, url, parent)
Deprecated. This function is deprecated and should not be used in new scripts.
Deprecated. Replaced by createWebAttachment on Page. Create a new Web Attachment.
Parameters
Name
Type
Description
title
String
the attachment title
url
String
the url of the attachment
parent
Page
the parent page
Return
Attachment -- this Attachment for chaining.
deleteSite()
Deprecated. This method is not currently implemented, and will become unavailable in the future.
Deletes this site.
var site = SitesApp.getSite('example.com', 'mysite');
site.deleteSite();
getAnnouncements()
Deprecated. This function is deprecated and should not be used in new scripts.
Retrieves a list of announcements for the given Google Site.
var site = SitesApp.getSite("example.com", "mysite");
var pages = site.getAnnouncements();
for(var i in pages)
Logger.log(pages[i].getTitle());
Return
Page[] -- an array of announcement @link Pageinstances
getAnnouncementsPages()
Deprecated. This function is deprecated and should not be used in new scripts.
Retrieves a list of announcements pages for the given Google Site.
var site = SitesApp.getSite("example.com", "mysite");
var pages = site.getAnnouncementsPages();
for(var i in pages)
Logger.log(pages[i].getTitle());
Return
Page[] -- an array of Page instances
getAttachments()
Deprecated. This function is deprecated and should not be used in new scripts.
Retrieves a list of attachments for the given Google Site.
var site = SitesApp.getSite("example.com", "mysite");
var attachments = site.getAttachments();
for(var i in attachments)
// Only hosted attachments have content types
Logger.log(attachments[i].getContentType());
Return
Attachment[] -- an array of Attachment instances
getCollaborators()
Deprecated. This function is deprecated and should not be used in new scripts.
Retrieves list of collaborators for the site
var collaborators = SitesApp.getSite('example.com', 'mysite').getCollaborators();
for(var i in collaborators)
Logger.log(collaborators[i].getEmail())
Return
User[] -- an array containing User instances representing collaborators
getFileCabinetPages()
Deprecated. This function is deprecated and should not be used in new scripts.
Retrieves a list of File Cabinet pages for the given Google Site.
var site = SitesApp.getSite("example.com", "mysite");
var pages = site.getFileCabinetPages();
for(var i in pages)
Logger.log(pages[i].getTitle());
Return
Page[] -- an array of Page instances
getListItems()
Deprecated. This function is deprecated and should not be used in new scripts.
Retrieves a list of site List items for the given Google Site.
var site = SitesApp.getSite("example.com", "mysite");
var listItems = site.getListItems();
for(var i in listItems)
Logger.log(listItems[i].getLastUpdated());
Return
ListItem[] -- an array of ListItem instances
getListPages()
Deprecated. This function is deprecated and should not be used in new scripts.
Retrieves a list of site List pages for the given Google Site.
var site = SitesApp.getSite("example.com", "mysite");
var pages = site.getListPages();
for(var i in pages)
Logger.log(pages[i].getTitle());
Return
Page[] -- an array of Page instances
getSelfLink()
Deprecated. This function is deprecated and should not be used in new scripts.
Retrieves the feed url of this Site.
var site = SitesApp.getSite('example.com', 'mysite');
var url = site.getSelfLink();
Return
String -- the url of this Site's feed
getSiteName()
Deprecated. This function is deprecated and should not be used in new scripts.
Return the siteName of the site
var site = SitesApp.getSite('example.com', 'mysite');
var url = site.getSelfLink();
Return
String -- the siteName of the site
getWebAttachments()
Deprecated. This function is deprecated and should not be used in new scripts.
Retrieves a list of web attachments for the given Google Site.
var site = SitesApp.getSite("example.com", "mysite");
var attachments = site.getWebAttachments();
for(var i in attachments)
// Only web attachments have URLs
Logger.log(attachments[i].getUrl());
Return
Attachment[] -- an array of Attachment instances
getWebPages()
Deprecated. This function is deprecated and should not be used in new scripts.
Retrieves a list of web pages for the given Google Site.
var site = SitesApp.getSite("example.com", "mysite");
var pages = site.getWebPages();
for(var i in pages)
Logger.log(pages[i].getTitle());
Return
Page[] -- an array of Page instances
removeCollaborator(email)
Deprecated. This function is deprecated and should not be used in new scripts.
Removes a collaborator from the site by user email
// This snippet removes the user with the given email from the collaborators list
var site = SitesApp.getSite('example.com', 'mysite');
site.removeCollaborator("[email protected]");
Parameters
Name
Type
Description
String
The email of the user to remove from the collaborators
Return
Site -- the site instance for method chaining
removeCollaborator(user)
Deprecated. This function is deprecated and should not be used in new scripts.
Removes a collaborator from the site
// This snippet removes the current user from the list of collaborators
var site = SitesApp.getSite('example.com', 'mysite');
site.removeCollaborator(Session.getActiveUser());
Parameters
Name
Type
Description
user
User
A user to remove from the list of collaborators
Return
Site -- the site instance for method chaining
https://developers.google.com/apps-script/reference/sites/site
Top Related