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 |
setTitle(title) | Site | Set 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
| Name | Type | Description |
|---|---|---|
emailAddress | String | The email address of the user to add. |
Return
Site — This Site, for chaining.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
| Name | Type | Description |
|---|---|---|
emailAddresses | String[] | An array of email addresses of the users to add. |
Return
Site — This Site, for chaining.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
addOwner(email)
Add a new owner to the website
var site = SitesApp.getSite("example.com", "mysite");
site.addOwner("eric@example.com");
Parameters
| Name | Type | Description |
|---|---|---|
email | String | The email of the user to add as an owner |
Return
Site — this site for chaining
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
| Name | Type | Description |
|---|---|---|
emailAddresses | String[] | An array of email addresses of the users to add. |
Return
Site — This Site, for chaining.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
createAnnouncementsPage(title, name, html)
Create a new announcements page. Note that a parent site or page cannot have more than 500 child pages.
// 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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
createFileCabinetPage(title, name, html)
Create a new file-cabinet 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.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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
createPageFromTemplate(title, name, template)
Create a new page from a template. 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 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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getEditors()
getName()
Return the name of the site
var name = SitesApp.getSite('example.com', 'mysite').getName();
Return
String — the name of this Site instance
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getSummary()
Return the summary of the web site
var summary = SitesApp.getSite('example.com', 'mysite').getSummary();
Return
String — the summary of this site
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getTheme()
Gets the theme of the site
var theme = SitesApp.getSite('example.com', 'mysite').getTheme();
Return
String — the theme of this site
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getTitle()
Return the title of the site
var title = SitesApp.getSite('example.com', 'mysite').getTitle();
Return
String — the title of this site
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getUrl()
Retrieves the url of this Site.
var url = SitesApp.getSite('example.com', 'mysite').getUrl();
Return
String — the url of this Site instance
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getViewers()
removeEditor(emailAddress)
Removes the given user from the list of editors for the Site. This method doesn't
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, or if the Site is in a shared drive that the user can access.
For Drive files, this also removes the user from the list of viewers.
Parameters
| Name | Type | Description |
|---|---|---|
emailAddress | String | The email address of the user to remove. |
Return
Site — This Site, for chaining.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
removeEditor(user)
Removes the given user from the list of editors for the Site. This method doesn't
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, or if the Site is in a shared drive that the user can access.
For Drive files, this also removes the user from the list of viewers.
Parameters
| Name | Type | Description |
|---|---|---|
user | User | A representation of the user to remove. |
Return
Site — This Site, for chaining.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
| Name | Type | Description |
|---|---|---|
email | String | The email of the user to remove from the owners |
Return
Site — the site instance for method chaining
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
doesn't 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, or if the Site is in a shared drive that the user can access.
For Drive files, this also removes the user from the list of editors.
Parameters
| Name | Type | Description |
|---|---|---|
emailAddress | String | The email address of the user to remove. |
Return
Site — This Site for chaining.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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 doesn't 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, or
if the Site is in a shared drive that the user can access.
For Drive files, this also removes the user from the list of editors.
Parameters
| Name | Type | Description |
|---|---|---|
user | User | A representation of the user to remove. |
Return
Site — This Site for chaining.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
| Name | Type | Description |
|---|---|---|
theme | String | a string name for the theme to set for this Site |
Return
Site — the site for method chaining
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds