Chapter 8. REST API

8.1. Overview

The portal provides a REST API to portal entities such as Sites, Pages, and Navigation. All data is sent and received as JSON.

8.1.1. Base URL

There are two base URLs for the REST API. One that will be used if you need to authenticate and one that can be used to access resources anonymously.
Anonymous Base URL
http://<host>:<port>/rest/managed-components/api
Authenticated Base URL
http://<host>:<port>/rest/private/managed-components/api

8.1.2. Authentication

The REST API supports basic authentication. Below is an example of using basic authentication in curl command.
curl -u <username> http://<host>:<port>/rest/private/managed-components/api
This allows users to access resources they have access to depending on the portal entity permissions.

Note

Only members of the group /platform/administrators are allowed to add, update, or delete resources.

8.1.3. Content Type

Since all data is sent and received using JSON, appropriate HTTP headers need to be included in each HTTP request.
For clients receiving data the following HTTP header needs to be included in the request
Accept: application/json
For clients sending data the following HTTP header needs to be included in the request
Content-Type: application/json

8.1.4. Localization

Localization is supported for navigation nodes that have localized displayNames. To specify the language simply add the Accept-Language header to the HTTP request.

Example 8.1. French Header

This examples describes the Accept-Language header used for French localization.
Accept-Language: fr

8.2. Resources

The following sections describe the resources available in the REST API.

Important

All URLs in the Example responses featured in this section are relative to the Base URL.

8.2.1. Sites

8.2.1.1. List Sites

Sites are organized by site type, where site-type can be site , space , or dashboard .

Example 8.2. Listing Sites using GET

This example describes the syntax required to list site types.
GET /api/{site-type}s/

Note

The 's' at the end of the URL is important. Space resolves to /api/spaces/ and dashboard resolves to /api/dashboards/.

Table 8.1. Additional Parameters for site-type

Parameter
Type
Default
Description
emptySites
boolean
false
Indicates to include empty sites (sites w/out pages or navigation)
offset
int
0
The offset of the results in a paginated request
limit
int
15
The maximum number of results to return in a paginated request

Example 8.3. List Sites using GET Request and Response

This example lists the sites that are available and their corresponding resource location. This should be used by clients instead of hard coding every location or URL.
GET /api/sites
HTTP/1.1 200 OK
Content-Type: application/json
[
    {
        "name" : "classic",
        "type" : "site",
        "url" : "/api/sites/classic"
    },
    {
        "name" : "mobile",
        "type" : "site",
        "url" : "/api/sites/mobile"
    }
]

Note

The url element is the full URL but for sake of brevity it is relative for the examples in this document.

8.2.1.2. Retrieve a Site

To retrieve a site named site-name the following syntax applies.
GET /api/{site-type}s/{site-name}

Example 8.4. Retrieve a Site Request and Response

This example shows how to retrieve the Classic site.
GET /api/sites/classic
HTTP/1.1 200 OK
Content-Type: application/json
{
    "name" : "classic",
    "type" : "site",
    "displayName" : "Classic",
    "description" : "GateIn default portal",
    "skin" : "Default",
    "locale" : "en",
    "access-permissions" : ["Everyone"],
    "edit-permissions" : ["*:/platform/administrators"],
    "attributes" : [
        {
            "key" : "showPortletInfo",
            "value" : "false"
        },
        {
            "key" : "sessionAlive",
            "value" : "onDemand"
        }
    ],
    "pages" : {"url" : "/api/sites/classic/pages"},
    "navigation" : {"url" : "/api/sites/classic/navigation"}
}

Note

The url element is the full URL but for sake of brevity it is relative for the examples in this document.

8.2.1.3. Create a site

To create a site named site-name, the following syntax applies:
POST /api/{site-type}s/{site-name}

Example 8.5. Create a Site Request and Response

This example creates a site named 'foo'.
POST /api/sites/foo
HTTP/1.1 200 OK
Content-Type: application/json
{
    "name" : "foo",
    "type" : "site",
    "displayName" : "Basic Portal",
    "description" : "This is basic portal template",
    "skin" : "Default",
    "locale" : "en",
    "access-permissions" : ["Everyone"],
    "edit-permissions" : ["*:/platform/administrators"],
    "attributes" : [{
        "key" : "sessionAlive",
        "value" : "onDemand"
    }],
    "pages" : {"url" : "/api/sites/foo/pages"},
    "navigation" : {"url" : "/api/sites/foo/navigation"}
}

Note

The url element is the full URL but for sake of brevity it is relative for the examples in this document.

8.2.1.4. Delete a site

To delete a site named site-name, the following syntax applies:
DELETE /api/{site-type}s/{site-name}

Example 8.6. Delete a Site Request and Response

This example deletes a site named 'foo'
DELETE /api/sites/foo
HTTP/1.1 200 OK
Content-Type: application/json

8.2.1.5. Update a site

To update a site named site-name, the following syntax applies:
PUT /api/{site-type}s/{site-name}

Example 8.7. Update a Site Request and Response

This example updates the site 'classic' with a new description "The Classic site shipped with the product".
PUT /api/sites/classic

Content-Type: application/json
{
   "description" : "The Classic site shipped with the product"
}
HTTP/1.1 200 OK
Content-Type: application/json
{
    "name" : "classic",
    "type" : "site",
    "displayName" : "Classic",
    "description" : "The Classic site shipped with the product !",
    "skin" : "Default",
    "locale" : "en",
    "access-permissions" : ["Everyone"],
    "edit-permissions" : ["*:/platform/administrators"],
    "attributes" : [
        {
            "key" : "showPortletInfo",
            "value" : "false"
        },
        {
            "key" : "sessionAlive",
            "value" : "onDemand"
        }
    ],
    "pages" : {"url" : "/api/sites/classic/pages"},
    "navigation" : {"url" : "/api/sites/classic/navigation"}
}

Note

The url element is the full URL but for sake of brevity it is relative for the examples in this document.

8.2.2. Pages

8.2.2.1. List Pages

To list pages in a site named site-name, the following syntax applies:
GET /api/{site-type}s/{site-name}/pages

Table 8.2. list-pages Additional Attributes

Parameter
Type
Default
Description
offset
int
0
The offset of the results in a paginated request
limit
int
15
The maximum number of results to return in a paginated request

Example 8.8. List all Pages Request and Response

This example shows how to list all pages for the site 'classic'.
GET /api/sites/classic/pages
HTTP/1.1 200 OK
Content-Type: application/json
[
    {
        "name" : "homepage",
        "siteType" : "site",
        "siteName" : "classic",
        "url" : "/api/sites/classic/pages/homepage"
    },
    {
        "name" : "register",
        "siteType" : "site",
        "siteName" : "classic",
        "url" : "/api/sites/classic/pages/register"
    },
    {
        "name" : "sitemap",
        "siteType" : "site",
        "siteName" : "classic",
        "url" : "/api/sites/classic/pages/sitemap"
    }
]

Note

The url element is the full URL but for sake of brevity it is relative for the examples in this document.

8.2.2.2. Retrieve a page

To retrieve a page named page-name, the following syntax applies:
GET /api/{site-type}s/{site-name}/pages/{page-name}

Example 8.9. Retrieve a Page Request and Response

This example shows how to retrieve the page 'homepage'
GET /api/sites/classic/pages/homepage
HTTP/1.1 200 OK
Content-Type: application/json
{
    "name" : "homepage",
    "displayName" : "Home Page",
    "description" : null,
    "access-permissions" : ["Everyone"],
    "edit-permissions" : ["*:/platform/administrators"]
}

8.2.2.3. Create a page

To create a page named page-name, the following syntax applies:
POST /api/{site-type}s/{site-name}/pages/{page-name}

Example 8.10. Create a New Page Request and Response

The following example creates a page named 'newpage'.
POST /api/sites/classic/pages/newpage
HTTP/1.1 200 OK
Content-Type: application/json
{
    "name" : "newpage",
    "displayName" : "newpage",
    "description" : null,
    "access-permissions" : ["Everyone"],
    "edit-permissions" : ["*:/platform/administrators"]
}

8.2.2.4. Delete a page

To delete a page named page-name, the following syntax applies:
DELETE /api/{site-type}s/{site-name}/pages/{page-name}

Example 8.11. Delete a Page Request and Response

This example deletes a page named 'newpage'.
DELETE /api/sites/classic/pages/newpage
HTTP/1.1 200 OK
Content-Type: application/json

8.2.2.5. Update a page

To update a page named page-name, the following syntax applies:
PUT /api/{site-type}s/{site-name}/pages/{page-name}

Example 8.12. Update Page Description Request and Response

This example updates the page 'homepage' with a new description.
PUT /api/sites/classic/pages/homepage

Content-Type: application/json
{
   "description" : "The default homepage"
}
HTTP/1.1 200 OK
Content-Type: application/json
{
    "name" : "homepage",
    "displayName" : "Home Page",
    "description" : "The default homepage",
    "access-permissions" : ["Everyone"],
    "edit-permissions" : ["*:/platform/administrators"]
}

8.2.3. Navigation

8.2.3.1. Retrieve Navigation

To update a page named site-name, the following syntax applies:
GET /api/{site-type}s/{site-name}/navigation

Table 8.3. Retrieve Navigation Parameters

Parameter
Type
Default
Description
scope
int
n/a
Specifies how many nodes to load (-1 for all)
Below is an example of retrieving the navigation for the site 'classic'

Example 8.13. Request

GET /api/sites/classic/navigation

Example 8.14. Response

HTTP/1.1 200 OK
Content-Type: application/json
{
    "priority" : 1,
    "siteType" : "site",
    "siteName" : "classic",
    "nodes" : [
        {
            "name" : "home",
            "url" : "/api/sites/classic/navigation/home"
        },
        {
            "name" : "sitemap",
            "url" : "/api/sites/classic/navigation/sitemap"
        }
    ]
}

Note

The url element is the full URL but for sake of brevity it is relative for the examples in this document.

Example 8.15. Scope Parameter Request and Response

This example uses the scope parameter to load more nodes which will include the actual node representation in the response
GET /api/sites/classic/navigation?scope=1
HTTP/1.1 200 OK
Content-Type: application/json
{
    "priority" : 1,
    "siteType" : "site",
    "siteName" : "classic",
    "nodes" : [
        {
            "name" : "home",
            "uri" : "/portal/classic/home",
            "isVisible" : true,
            "visibility" : {"status" : "VISIBLE"},
            "iconName" : null,
            "displayName" : "Home",
            "displayNames" : [...]
            "children" : null,
            "page" : {
                "pageName" : "homepage",
                "siteName" : "classic",
                "siteType" : "site",
                "url" : "/api/sites/classic/pages/homepage"
            }
        },
        {
            "name" : "sitemap",
            "uri" : "/portal/classic/sitemap",
            "isVisible" : true,
            "visibility" : {"status" : "VISIBLE"},
            "iconName" : null,
            "displayName" : "SiteMap",
            "displayNames" : [...]
            "children" : null,
            "page" : {
                "pageName" : "sitemap",
                "siteName" : "classic",
                "siteType" : "site",
                "url" : "/api/sites/classic/pages/sitemap"
            }
        }
    ]
}

Note

The url element is the full URL but for sake of brevity it is relative for the examples in this document.

8.2.3.2. Retrieve a node

To retrieve a node with path node-path, the following syntax applies:
GET /api/{site-type}s/{site-name}/navigation/{node-path}

Table 8.4. Node Path Parameters

parameter
type
default
description
scope
int
n/a
Specifies how many nodes to load (-1 for all)

Example 8.16. Retrieve a Node Request and Response

This example retrieves the node 'home'.
GET /api/sites/classic/navigation/home
HTTP/1.1 200 OK
Content-Type: application/json
{
    "name" : "home",
    "uri" : "/portal/classic/home",
    "isVisible" : true,
    "visibility" : {"status" : "VISIBLE"},
    "iconName" : null,
    "displayName" : "Home",
    "displayNames" : [...]
    "children" : null,
    "page" : {
        "pageName" : "homepage",
        "siteName" : "classic",
        "siteType" : "site",
        "url" : "/api/sites/classic/pages/homepage"
    }
}
You can control the displayName value for localized nodes with the Accept-Language header.

Example 8.17. Accept-Language Request and Response

This example retrieves the node 'home' to display the displayName in French.
GET /api/sites/classic/navigation/home
Accept-Language: fr
HTTP/1.1 200 OK
Content-Type: application/json
{
    "name" : "home",
    "uri" : "/portal/classic/home",
    "isVisible" : true,
    "visibility" : {"status" : "VISIBLE"},
    "iconName" : null,
    "displayName" : "Accueil",
    "displayNames" : [...]
    "children" : null,
    "page" : {
        "pageName" : "homepage",
        "siteName" : "classic",
        "siteType" : "site",
        "url" : "/api/sites/classic/pages/homepage"
    }
}

Note

The url element is the full URL but for sake of brevity it is relative for the examples in this document.

8.2.3.3. Create a node

To create a node with path node-path, the following syntax applies:
POST /api/{site-type}s/{site-name}/navigation/{node-path}

Example 8.18. Create a Node Request and Response

This example creates a new node 'newnode' under the home navigation node.
POST /api/sites/classic/navigation/home/newnode
HTTP/1.1 200 OK
Content-Type: application/json
{
    "name" : "newnode",
    "uri" : "/portal/classic/home/newnode",
    "isVisible" : true,
    "visibility" : {"status" : "VISIBLE"},
    "iconName" : null,
    "displayName" : "newnode",
    "children" : null,
    "page" : null
}

8.2.3.4. Delete a node

To delete a node with path node-path, the following syntax applies:
DELETE /api/{site-type}s/{site-name}/navigation/{node-path}

Example 8.19. Delete Node Request and Response

This example deletes a node 'newnode'.
DELETE /api/sites/classic/navigation/home/newnode
HTTP/1.1 200 OK
Content-Type: application/json

8.2.3.5. Update a node

To update a node with path node-path, the following syntax applies:
PUT /api/{site-type}s/{site-name}/navigation/{node-path}

Example 8.20. Update Node Request and Response

Below is an example of updating the node 'home' to point to the sitemap page rather then the homepage.
PUT /api/sites/classic/navigation/home

Content-Type: application/json
{
   "page" : {
        "pageName" : "sitemap",
        "siteName" : "classic",
        "siteType" : "site"
   }
}
HTTP/1.1 200 OK
Content-Type: application/json
{
    "name" : "home",
    "uri" : "/portal/classic/home",
    "isVisible" : true,
    "visibility" : {"status" : "VISIBLE"},
    "iconName" : null,
    "displayName" : "Test",
    "displayNames" : [...]
    "children" : null,
    "page" : {
        "pageName" : "sitemap",
        "siteName" : "classic",
        "siteType" : "site",
        "url" : "/api/sites/classic/pages/sitemap"
    }
}

Note

The url element is the full URL but for sake of brevity it is relative for the examples in this document.

Example 8.21. Update displayName Request and Response

This example updates the English localized displayName to 'Home Page'.
PUT /api/sites/classic/navigation/home

Content-Type: application/json
{
    "displayNames" : [
        {
            "value" : "ホーム",
            "lang" : "ja"
        },
        {
            "value" : "Home Page",
            "lang" : "en"
        },
        {
            "value" : "首頁",
            "lang" : "zh-TW"
        },
        {
            "value" : "Domů",
            "lang" : "cs"
        },
        {
            "value" : "Accueil",
            "lang" : "fr"
        },
        {
            "value" : "主页",
            "lang" : "zh"
        },
        {
            "value" : "Главная",
            "lang" : "ru"
        },
        {
            "value" : "ترحيب",
            "lang" : "ar"
        },
        {
            "value" : "Trang chủ",
            "lang" : "vi"
        },
        {
            "value" : "Home",
            "lang" : "nl"
        },
        {
            "value" : "Inicio",
            "lang" : "es"
        },
        {
            "value" : "Principal",
            "lang" : "pt-BR"
        },
        {
            "value" : "Startseite",
            "lang" : "de"
        },
        {
            "value" : "홈",
            "lang" : "ko"
        },
        {
            "value" : "Home",
            "lang" : "it"
        },
        {
            "value" : "Додому",
            "lang" : "uk"
        },
        {
            "value" : "गृह पृष्‍ठ",
            "lang" : "ne"
        }
    ]
}
HTTP/1.1 200 OK
Content-Type: application/json
{
    "name" : "home",
    "uri" : "/portal/classic/home",
    "isVisible" : true,
    "visibility" : {"status" : "VISIBLE"},
    "iconName" : null,
    "displayName" : "Home Page",
    "displayNames" : [
        {
            "value" : "ホーム",
            "lang" : "ja"
        },
        {
            "value" : "Home Page",
            "lang" : "en"
        },
        {
            "value" : "首頁",
            "lang" : "zh-TW"
        },
        {
            "value" : "Domů",
            "lang" : "cs"
        },
        {
            "value" : "Accueil",
            "lang" : "fr"
        },
        {
            "value" : "主页",
            "lang" : "zh"
        },
        {
            "value" : "Главная",
            "lang" : "ru"
        },
        {
            "value" : "ترحيب",
            "lang" : "ar"
        },
        {
            "value" : "Trang chủ",
            "lang" : "vi"
        },
        {
            "value" : "Home",
            "lang" : "nl"
        },
        {
            "value" : "Inicio",
            "lang" : "es"
        },
        {
            "value" : "Principal",
            "lang" : "pt-BR"
        },
        {
            "value" : "Startseite",
            "lang" : "de"
        },
        {
            "value" : "홈",
            "lang" : "ko"
        },
        {
            "value" : "Home",
            "lang" : "it"
        },
        {
            "value" : "Додому",
            "lang" : "uk"
        },
        {
            "value" : "गृह पृष्‍ठ",
            "lang" : "ne"
        }
    ],
    "children" : null,
    "page" : {
        "pageName" : "homepage",
        "siteName" : "classic",
        "siteType" : "site",
        "url" : "/api/sites/classic/pages/homepage"
    }
}

Note

The url element is the full URL but for sake of brevity it is relative for the examples in this document.

Note

We have to include all the displayNames since the REST API will overwrite the values on the server with whatever we supply in the request.
Since the REST API overwrites the displayNames field we can delete existing displayNames by simply not including them.

Example 8.22. Deleting All Localized Display Names Except for English Request and Response

This example deletes all localized displayNames except for English.
PUT /api/sites/classic/navigation/home

Content-Type: application/json
{
    "displayNames" : [
        {
            "value" : "Home",
            "lang" : "en"
        }
    ]
}
HTTP/1.1 200 OK
Content-Type: application/json
{
    "name" : "home",
    "uri" : "/portal/classic/home",
    "isVisible" : true,
    "visibility" : {"status" : "VISIBLE"},
    "iconName" : null,
    "displayName" : "Home",
    "displayNames" : [
        {
            "value" : "Home Page",
            "lang" : "en"
        }
    ],
    "children" : null,
    "page" : {
        "pageName" : "homepage",
        "siteName" : "classic",
        "siteType" : "site",
        "url" : "/api/sites/classic/pages/homepage"
    }
}

Note

The url element is the full URL but for sake of brevity it is relative for the examples in this document.

Example 8.23. Removing Localized Display Names Request and Response

This example removes all localized displayNames from the home navigation node and replaces them with a non-localized (simple) displayName 'Home'.
PUT /api/sites/classic/navigation/home

Content-Type: application/json
{
    "displayName" : "Home"
}
HTTP/1.1 200 OK
Content-Type: application/json
{
    "name" : "home",
    "uri" : "/portal/classic/home",
    "isVisible" : true,
    "visibility" : {"status" : "VISIBLE"},
    "iconName" : null,
    "displayName" : "Home",
    "displayNames" : [{"value" : "Home"}]
    "children" : null,
    "page" : {
        "pageName" : "homepage",
        "siteName" : "classic",
        "siteType" : "site",
        "url" : "/api/sites/classic/pages/homepage"
    }
}

8.2.4. Working with Templates

Portal administrators use templates to update existing portal, group, and user sites. Templates are also used to create new sites.
The scenarios described here explain the objective of templates.

Example 8.24. Portal Site Template

Consider a portal with 100 portal sites created from template A and 50 portal sites created from template B. A portal administrator wants to add two new pages to sites created from template A and three new pages to sites created from template B.
Using templates the portal administrator can perform this operation by using a single template for sites with two new pages created using template A and a single template for sites with three new pages created using template B.

Example 8.25. Group Site Template

Consider a portal with 20 different navigation groups. A portal administrator wants to add three new pages to ten navigation groups.
Using templates, the portal administrator can perform this operation by applying a single template to ten navigation groups.

Example 8.26. User Site Template

Consider a portal with 1000 users with individual dashboards. A portal administrator wants to modify the layout of the dashboards, or add new pages and navigation nodes for all the users.
In the absence of templates, the portal administrator uses the REST management API to perform this operation. The administrator exports all dashboards, modifies each dashboard and imports the modified dashboards with a merge strategy.
Using templates the portal administrator can perform the same operation by using a single template for all the dashboards.

8.2.4.1. Portal Site Template

To create a Portal site template, download the template using PUT command.
PUT http://<host>:<port>/rest/private/managed-components/template/portal Content-Type: application/zip .
The template file is a .zip file with following structure:
/portal
/portal/template
/portal/template/<name_of_template1>
/portal/template/<name_of_template1>/navigation.xml
/portal/template/<name_of_template1>/pages.xml
/portal/template/<name_of_template1>/portal.xml
/portal/template/<name_of_template2>
/portal/template/<name_of_template2>/navigation.xml
/portal/template/<name_of_template2>/pages.xml
/portal/template/<name_of_template2>/portal.xml
...

Portal site template parameters

importMode
String with default setting as merge.
Possible values: conserve, insert, merge, and overwrite
targetSite
String with default value set to all sites.
If this targetSite attribute is not present template is applied in all portals created from templates defined in .zip. This attribute allows to filter and define in which sites this operation is performed. This attribute can have multiple instances of itself.

Example 8.27. Create a Portal Site Using Curl Tool

Run the curl tool command.
$ curl -i -H "Content-Type: application/zip" -u root:gtn -X PUT -T "template-templateA.zip" http://localhost:8080/rest/private/managed-components/template/portal?importMode=merge&targetSite=site1&targetSite=site2
The output of the command.
Where template-templateA.zip:

portal/template/templateA/navigation.xml
portal/template/templateA/pages.xml
portal/tempalte/templateA/portal.xml
Result:
Updates only site1 and site2 of sites created from templateA.

8.2.4.2. Group Sites Template

To create a Group site template, download the template using the PUT command.
PUT http://<host>:<port>/rest/private/managed-components/template/group Content-Type: application/zip
The template file is a .zip file with following structure:
//group
/group/template
/group/template/navigation.xml
/group/template/pages.xml
/group/template/group.xml
...

Group site template parameters

importMode
String with default setting as merge.
Data import strategy. Possible values: conserve, insert, merge, overwrite
targetSite
String with default value set to all sites.
If this targetGroup attribute is not present template is applied in all group sites. This attribute allows to filter and define the sites on which this operation is performed. This attribute can have multiple instances of itself.

Example 8.28. Create Group Site using Curl Tool

Run the curl tool command.
$ curl -i -H "Content-Type: application/zip" -u root:gtn -X PUT -T "template-group.zip" http://localhost:8080/rest/private/managed-components/template/group?importMode=merge&targetGroup=myorg/mygroup1&targetGroup=myorg/mygroup2
The output of the command
Where template-group.zip:

group/template/navigation.xml
group/template/pages.xml
group/tempalte/group.xml
Result:
"myorg/mygroup1" and "myorg/mygroup2" groups sites created are updated with MERGE strategy using template defined in template-group.zip.

8.2.4.3. User Sites Template

To create a User site template, download the template using the PUT command.
PUT http://<host>:<port>/rest/private/managed-components/template/user Content-Type: application/zip
The template file is a .zip file with following structure:
/user
/user/template
/user/template/navigation.xml
/user/template/pages.xml
/user/template/user.xml
...

Group site template parameters

importMode
String with default setting as merge.
Data import strategy. Possible values: conserve, insert, merge, and overwrite
targetExpr
String with default value set to all users.
This attribute defines a search expression for user sites on which the template operation is performed. This attribute has priority over targetUser attribute.
targetUser
Is a String with default value set to all users.
If targetExpr is not defined, targetUser can define user target for template operation. This attribute can have multiple instances.
dashboardMode
String with default value set to none.
Creates dashboard for user. If this attribute is not present template is applied on users with a dashboard. Possible values: create.

Example 8.29. User Site using Curl Tool

Run the curl tool command.
$ curl -i -H "Content-Type: application/zip" -u root:gtn -X PUT -T "template-user.zip" http://localhost:8080/rest/private/managed-components/template/user?importMode=merge&targetExpr=user*
The output of the command
Where template-user.zip:

user/template/navigation.xml
user/template/pages.xml
user/template/user.xml
Result:
All dashboards from users starting with "user" updated with MERGE strategy using template defined in template-user.zip