Google Apps Script

Class SitesApp

Create and access Google Sites.

Properties

PropertyTypeDescription
AttachmentTypeAttachmentType
PageTypePageType

Methods

MethodReturn typeBrief description
copySite(domain, name, title, summary, site)SiteCreates a new Site by copying an existing Site.
createSite(domain, name, title, summary)SiteCreates a new Site.
getActivePage()PageReturns the active page, if the script is hosted in a container, or null otherwise.
getActiveSite()SiteReturns the active container, if the script is hosted in a container, or null otherwise.
getAllSites(domain)Site[]Retrieves first page of Sites belonging to this domain.
getAllSites(domain, start, max)Site[]Retrieves all Sites belonging to this domain.
getPageByUrl(url)PageRetrieves a Page by url.
getSite(name)SiteRetrieves a Site for the given Google Site, if the user is a consumer who does not have a hosted domain.
getSite(domain, name)SiteRetrieves a Site for the given Google Site.
getSiteByUrl(url)SiteRetrieves a Site by url.
getSites()Site[]Retrieves first page of Sites for a user, if the user is a consumer who does not have a hosted domain.
getSites(start, max)Site[]Retrieves Sites for a user between the given bounds if the user is a consumer who does not have a hosted domain.
getSites(domain)Site[]Retrieves first page of Sites belonging to this user in this domain.
getSites(domain, start, max)Site[]Retrieves all Sites belonging to this user in this domain for the given range given.

Detailed documentation

copySite(domain, name, title, summary, site)

Creates a new Site by copying an existing Site. Warning: Copying a site takes time, from seconds to possibly many minutes, depending on the size of the site. Although the method returns right away, the copy is still going on in the background, and not all pages in the copied site will be immediately available. This method can also be used to instantiate a new site based on a given template.

 
// This creates a site. Note that this only works for Google Apps domains.
 // There is no version of this API for consumer accounts.
 var site = SitesApp.createSite("example.com",
                                "homepage",
                                "My Home Page",
                                "This is a new site I created!");

 var siteCopy = SitesApp.copySite("example.com",
                                  "homepage-clone",
                                  "Cloned Home Page",
                                  "Begun, these clone wars have.",
                                  site);
 

Parameters

NameTypeDescription
domainStringThe Google Apps hosted domain (e.g. example.com)
nameStringThe webspace name found in the URL (e.g. mySite)
titleStringThe title of the site
summaryStringThe description of the site
siteSiteThe Site to copy from. This can either be a site or a template. If the parameter is an existing site then the entire contents of the site will be copied. If the given Site is a template, then a new Site is created based on that template.

Return

Site — The site that was copied. Note that the copy is asynchronous, and the copy operation may still be ongoing even though a reference to the site has been returned.


createSite(domain, name, title, summary)

Creates a new Site.

 
// This creates a site. Note that this only works for Google Apps domains.
 // There is no version of this API for consumer accounts.
 var site = SitesApp.createSite("example.com",
                                "homepage",
                                "My Home Page",
                                "This is a new site I created!");
 

Parameters

NameTypeDescription
domainStringThe Google Apps hosted domain (e.g. example.com)
nameStringthe path name found in the URL (e.g. mySite)
titleStringThe title of the site
summaryStringThe description of the site

Return

Site — The created site


getActivePage()

Returns the active page, if the script is hosted in a container, or null otherwise.

 
var site = SitesApp.getActivePage();
 

Return

Page — the active container if it is a sites page


getActiveSite()

Returns the active container, if the script is hosted in a container, or null otherwise.

 
var site = SitesApp.getActiveSite();
 

Return

Site — the active container if it is a site


getAllSites(domain)

Retrieves first page of Sites belonging to this domain.

 
// This writes the first page of sites belonging to a Google Apps
 // domain to the log.
 var sites = SitesApp.getAllSites("example.com");
 for(var i in sites) {
   Logger.log(sites[i].getUrl());
 }
 

Parameters

NameTypeDescription
domainStringThe Google Apps hosted domain (e.g. example.com)

Return

Site[] — an array of sites belonging to the domain


getAllSites(domain, start, max)

Retrieves all Sites belonging to this domain.

 
// This writes the a list of sites owned by the user running
 // the script in positions bounded by the start and max values to the log.
 var sites = SitesApp.getAllSites("example.com", 25, 50);
 for(var i in sites) {
   Logger.log(sites[i].getUrl());
 }
 

Parameters

NameTypeDescription
domainStringThe Google Apps hosted domain (e.g. example.com)
startIntegerthe index of the first site to return
maxIntegerthe maximum number of results to return

Return

Site[] — an array of sites belonging to the domain


getPageByUrl(url)

Retrieves a Page by url.

 
// This snippet retrieves the page at the given URL.
 // Throws an Invalid argument exception if the page does not exist or if
 // the URL given is invalid
 var page = SitesApp.getPageByUrl(
                     "https://sites.google.com/site/demositeappsscript/mylistpage");
 Logger.log(page.getName());
 

Parameters

NameTypeDescription
urlStringthe public url

Return

Page — a Page instance corresponding to the page at the URL


getSite(name)

Retrieves a Site for the given Google Site, if the user is a consumer who does not have a hosted domain.

 
// Returns a Site instance
 var site = SitesApp.getSite('mysite');
 

Parameters

NameTypeDescription
nameStringThe webspace name found in the URL (e.g. mySite)

Return

Site — A Site instance corresponding to a consumer site


getSite(domain, name)

Retrieves a Site for the given Google Site.

 
// Returns a Site instance
 var site = SitesApp.getSite('example.com', 'mysite');
 

Parameters

NameTypeDescription
domainStringThe Google Apps hosted domain (e.g. example.com)
nameStringThe webspace name found in the URL (e.g. mySite)

Return

Site — A Site instance corresponding to a hosted domain


getSiteByUrl(url)

Retrieves a Site by url.

 
// This snippet retrieves the site at the given URL
 // Throws an Invalid argument exception if the site does not exist or if
 // the URL given is invalid
 var site = SitesApp.getSiteByUrl("https://sites.google.com/site/demosite");
 Logger.log(site.getName());
 

Parameters

NameTypeDescription
urlStringthe public url

Return

Site — a Site found at the given URL


getSites()

Retrieves first page of Sites for a user, if the user is a consumer who does not have a hosted domain.

 
// This writes the first page of sites owned by the user running
 // the script to the log.
 var sites = SitesApp.getSites();
 for(var i in sites) {
   Logger.log(sites[i].getUrl());
 }
 

Return

Site[] — An array of sites beloning to the user running the script


getSites(start, max)

Retrieves Sites for a user between the given bounds if the user is a consumer who does not have a hosted domain.

 
var sites = SitesApp.getSites(25, 50);
 for(var i in sites) {
   Logger.log(sites[i].getUrl());
 }
 

Parameters

NameTypeDescription
startIntegerthe index of the first site to return
maxIntegerthe maximum number of results to return

Return

Site[] — an array of all the sites owned for a user


getSites(domain)

Retrieves first page of Sites belonging to this user in this domain.

 
// This writes the first page of sites owned by the user running
 // the script to the log.
 var sites = SitesApp.getSites("example.com");
 for(var i in sites) {
   Logger.log(sites[i].getUrl());
 }
 

Parameters

NameTypeDescription
domainStringThe Google Apps hosted domain (e.g. example.com)

Return

Site[] — An array of sites beloning to the user running the script


getSites(domain, start, max)

Retrieves all Sites belonging to this user in this domain for the given range given.

 
// This writes the a list of sites owned by the user running
 // the script in positions bounded by the start and max values to the log.
 var sites = SitesApp.getSites("example.com", 25, 50);
 for(var i in sites) {
   Logger.log(sites[i].getUrl());
 }
 

Parameters

NameTypeDescription
domainStringThe Google Apps hosted domain (e.g. example.com)
startIntegerthe index of the first site to return
maxIntegerthe maximum number of results to return

Return

Site[] — an array of sites belonging to the user

Authentication required

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

Signing you in...

Google Developers needs your permission to do that.