Create and access Google Sites.
Properties
| Property | Type | Description |
|---|---|---|
AttachmentType | AttachmentType | |
PageType | PageType |
Methods
| Method | Return type | Brief description |
|---|---|---|
copySite(domain, name, title, summary, site) | Site | Creates a new Site by copying an existing Site. |
createSite(domain, name, title, summary) | Site | Creates a new Site. |
getActivePage() | Page | Returns the active page, if the script is hosted in a container, or null otherwise. |
getActiveSite() | Site | Returns the active container, if the script is hosted in a container, or null otherwise. |
getAllSites(domain) | Site[] | Retrieves first 200 Sites belonging to this domain. |
getAllSites(domain, start, max) | Site[] | Retrieves all Sites belonging to this domain. |
getPageByUrl(url) | Page | Retrieves a Page by url. |
getSite(name) | Site | Retrieves a Site for the given Google Site, if the user is a consumer who does not have a hosted domain. |
getSite(domain, name) | Site | Retrieves a Site for the given Google Site. |
getSiteByUrl(url) | Site | Retrieves 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 G Suite 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
| Name | Type | Description |
|---|---|---|
domain | String | The G Suite hosted domain (e.g. example.com) |
name | String | The webspace name found in the URL (e.g. mySite) |
title | String | The title of the site |
summary | String | The description of the site |
site | Site | The 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.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
createSite(domain, name, title, summary)
Creates a new Site.
// This creates a site. Note that this only works for G Suite 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
| Name | Type | Description |
|---|---|---|
domain | String | The G Suite hosted domain (e.g. example.com) |
name | String | the path name found in the URL (e.g. mySite) |
title | String | The title of the site |
summary | String | The description of the site |
Return
Site — The created site
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getAllSites(domain)
Retrieves first 200 Sites belonging to this domain. To get all the sites, use the getAllSites(domain, start, max) method to page through the results.
// This writes the first page of sites belonging to a G Suite
// domain to the log.
var sites = SitesApp.getAllSites("example.com");
for(var i in sites) {
Logger.log(sites[i].getUrl());
}
Parameters
| Name | Type | Description |
|---|---|---|
domain | String | The G Suite hosted domain (e.g. example.com) |
Return
Site[] — an array of sites belonging to the domain
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getAllSites(domain, start, max)
Retrieves all Sites belonging to this domain.
// This writes the a list of sites in domain example.com to the log.
var pageStart = 0;
var pageSize = 50;
while (true) {
Logger.log("Loading sites starting at %s", pageStart);
var sites = SitesApp.getAllSites("example.com", pageStart, pageSize);
if (sites.length == 0) {
break;
}
Logger.log("Got %s sites back", sites.length);
pageStart += sites.length;
for(var i in sites) {
Logger.log("Found site: %s", sites[i].getUrl());
}
}
Parameters
| Name | Type | Description |
|---|---|---|
domain | String | The G Suite hosted domain (e.g. example.com) |
start | Integer | the index of the first site to return |
max | Integer | the maximum number of results to return |
Return
Site[] — an array of sites belonging to the domain
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getPageByUrl(url)
Retrieves a Page by url.
// This snippet retrieves the page at the given URL.
// Returns null 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
| Name | Type | Description |
|---|---|---|
url | String | the public url |
Return
Page — a Page instance corresponding to the page at the URL or null if the page does
not exist.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
| Name | Type | Description |
|---|---|---|
name | String | The webspace name found in the URL (e.g. mySite) |
Return
Site — A Site instance corresponding to a consumer site
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getSite(domain, name)
Retrieves a Site for the given Google Site.
// Returns a Site instance
var site = SitesApp.getSite('example.com', 'mysite');
Parameters
| Name | Type | Description |
|---|---|---|
domain | String | The G Suite hosted domain (e.g. example.com) |
name | String | The webspace name found in the URL (e.g. mySite) |
Return
Site — A Site instance corresponding to a hosted domain
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
| Name | Type | Description |
|---|---|---|
url | String | the public url |
Return
Site — a Site found at the given URL
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
| Name | Type | Description |
|---|---|---|
start | Integer | the index of the first site to return |
max | Integer | the maximum number of results to return |
Return
Site[] — an array of all the sites owned for a user
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
| Name | Type | Description |
|---|---|---|
domain | String | The G Suite hosted domain (e.g. example.com) |
Return
Site[] — An array of sites beloning to the user running the script
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
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
| Name | Type | Description |
|---|---|---|
domain | String | The G Suite hosted domain (e.g. example.com) |
start | Integer | the index of the first site to return |
max | Integer | the maximum number of results to return |
Return
Site[] — an array of sites belonging to the user
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds