Getting started with the types API
The types REST API endpoint is available as of Sitevision 2023.11.1 and its accompanying "pin/unpin content" friend is available as of Sitevision 2024.01.1
The Types API was introduced in the Sitevision 2023.11.1 release. Types is a contextless REST API endpoint that is used to lookup page data in a structured manner - regardless of where the data is located in the page structure. A template defines the specific type and the contents of the template defines the fields of the type.
The "pin/unpin content" concept that was introduced in the Sitevision 2024.01.1 release complements the Types API by prohibiting page editors to inadvertently sabotage the types schema when working with specifik pages and their content.
Permissions
To properly setup the type and fields for the Types API, two permissions are required:
- MANAGE_TYPES_IDENTIFIERS permission is required to administer the type and fields for the Types API.
- MANAGE_PINNING permission is required to pin and unpin modules (i.e. "seal the fields" of the Types API).
These permissions should typically only be assigned to the role/roles of more advanced (super) users of the site.
Example schema - how to setup a type with mandatory and optional fields
The template depicts the type and the modules of the page depicts the fields of the type. The type name is given by the technical identifier of the template and the field names are given by the technical identifiers of each module.
Note that a module that is denoted as a field must have Headless support in order to provide data to consumers of the Types API. The Text module and the Image module of Sitevision has built-in Headless support. WebApp modules must explicitly implement Headless support to provide data.
Step 1 - Register the type
Navigate to the Templates view and open Properties for the designated Template. Locate the technical identifier and enter the name of the type. In this example we specify "activity" as the type name.
Step 2 - Register the fields of the type
Fields of the type are depicted via some or all modules of the type (i.e. the Template). Open properties for the designated module/modules and locate the technical identifier section. Specify the name of the field. In this example we specify three fields: "title", "description" and "image". All three modules supports Headless (Text module and Image module).
Step 3 - Determine mandatory vs optional fields
The pin/unpin feature can be used to depict all mandatory fields (i.e. mandatory modules). A user that creates pages and articles typically can't delete pinned modules if the permissions are properly setup for the editor role of the site. Deleting a module that is specified as a field (or change the identifier) would screw up the intended type schema.
Right-click on the mandatory modules and select Pin in the menu to pin them. In this example we decide that the "title" and "description" fields are mandatory and the "image" field is optional. Hence we pin two modules.
The type schema is now properly setup so we publish the template.
Step 4 - Start creating type entries
When the template is ready to use, we can allow the page editors to start creating content as usual, i.e. in this case - creating articles. In this example we create two articles.
Step 5 - Use the Types API to extract data
The Types endpoint is part ot the Sitevision REST API. It is a contextless endpoint, i.e. is not bound to any node in the data/model tree of the site.
This is an example of the most basic usage of the Types API you can do - a GET request without any custom options. The type we created in step one is named "activity" and the site domain in this example is localhost.
GET https://localhost/rest-api/1/1/types/activity
The Types also supports custom options. The documentation is available as part of the REST API docs of your own site:
https://MY_DOMAIN/rest-api/doc/methods/types
NOTE! Access to the REST API docs requires the DEVELOPER permission and the REST API must also be enabled for the site.
Server-side invocation of the Types API
The Types endpoint can also be invoked server-side by WebApps and RESTApps via the RestApi utility. The Root Node is used as context.