originally posted May 2019 | 🕐️ 8 minute read
Introduction
This article will explain how to use and extend the REST API. It should be read in conjunction with the Content Server 16.2 API Reference.
The REST API (as its name may imply) is a web API implementation using the HTTP protocol and REST principles. While Content Server already has APIs accessible by the web (WebNode, WebServices), this one is lighter and easier to use.
The REST API layer is very thin, with csNode (a wrapper for LLNode) driving most of the requests. Therefore, almost no modification is needed at the REST API layer; unless it needs to do something that csNode does not provide. Since csNode is such a large component, please refer to the document entitled CSNODE Quick Start Guide.
This document assumes the reader has knowledge of the Builder (10.0.x) and/or the Content Server IDE (10.5.x) and basic knowledge of REST.
The REST API has a convenience method to create mappings. Currently, the Content Server IDE implementation is a multi-step process.
Overview
Below is a high-level diagram showing the workflow of the REST API. Aside from a handful of resources, the bulk of the REST API is a series of mappings. Each REST URL is linked to a particular function in a given resource. The main resource, CSNodes, is a lightweight resource that communicates with csNode. Any action in csNode can be executed from the REST API with no modification to the CSNodes resource (a mapping may be required to expose that functionality).
Using the REST API
The REST API can be consumed in a variety of ways, so the examples will be generic (you may need to do additional steps for a given client).
Using a REST client (browser add-on) will allow you interact with the API without having to write additional code (for testing purposes). You will need to define a few headers for this to work.
Form Header:
name: Content-Type
value: application/x-www-form-urlencoded OR application/multpart/fom-data
PUSH or PUT tend to use the application/multipart/form-data content-type
Authentication Header (the value can be obtained from an Auth call):
name: OTCSTICKET
value:
Each REST call is a URL, in the format:
http(s)://<machine name>/<CS service name>/<CS CGI>/api/v1/<resource name>
The examples in this document will be a relative path to the Content Server CGI. Values in angle brackets (<>) are placeholders and not literal values.
This document will only describe a handful of calls, for more information see the documentation in Swagger.
Troubleshooting
Make sure you use the correct HTTP verb for a given URL.
If the verb is PUT or POST, make sure the form header is active, otherwise the contents of the body will not be parsed properly. The request may return 200 but the state will remain unchanged.
Make sure the authentication header is active and contains a valid OTCSTICKET, otherwise you will get a 401 error. The auth call is the only exception.
To specify multiple values for the same parameter, repeat the parameter. For example:
api/v1/nodes/<id>/nodes?where_type=0&where_type=144
Please note that the parameters in the Body
portion of the call are not actually of the form parameter1=<value1>;parameter2=<value2>
etc. In practice they actually appear as parameter1=value1;parameter2=value2
.
Auth
This resource only has a single call, which allows a user to authenticate with Content Server.
Method: POST
URL: api/v1/auth
Body: username=<username>;password=<password>
A successful response should return a ticket, which can be used to populate the authentication header (without the quotation marks). You will not be able to access any other resources without a valid OTCSTICKET.
Nodes
The bulk of the REST API's are located in this resource which leverages csNode.
Get
This call will get metadata for the specified node ID.
Method: GET
URL: api/v1/nodes/<id>
The return values may include:
- data: property values
- definitions: definitions for each property value
- definitions_order: suggested ordering for each property
- definitions_map: relationship between definitions
- definitions_base: names of common properties across subtypes
- type: the subtype of the given node ID
- type_name: the display name of the subtype
- type_info: characteristics of the subtype
- available_actions: supported actions for the subtype
- available_roles: supported roles for the subtype
- addable_types: supported child subtypes
In data, if a given property is an identifier and has been given a persona in csNode (node, member, user, group, storage_provider), extended information can be returned.
Method: GET
URL: api/v1/nodes/<id>?expand=<persona>
Browse
This call will return information about the children for the specified node ID. This can be called without parameters, defaulting to page 1, limit 25 and sort asc_name.
Method: GET
URL: api/v1/nodes/<id>/nodes
The return values may include:
- data: property values for each child
- definitions: definitions for each property value
- limit: maximum number of items to return [Integer]
- page: current page number [Integer]
- page_total: total number of pages
- total_count: total number of items
- range_min: offset (min)
- range_max: offset (max)
- sort: column name used in sort [String], in the format [asc][desc]_{column name}
- where_name: name filter [String]
- where_type: subtype filter [Integer]
- where_facet: facet filter [String], in the format {facet id}:{facet value}
To alter the browse results, change one or more of the following parameters: limit, page, sort, where_name, where_type, where_facet.
Method: GET
URL: api/v1/nodes/<id>/nodes?page=<page number>&where_type=<subtype>
In data, if a given property is an identifier and has been given a persona in csNode (node, member, user, group, storage_provider), extended information can be returned.
Method: GET
URL: api/v1/nodes/<id>/nodes?expand=<persona>
Troubleshooting
Currently, where_type and where_facet cannot be used together.
To specify “all containers” in the where_type filter, use -1.
Create
This call will create an item using the specified parameters.
Method: POST
URL: api/v1/nodes
Body: type=<subtype>;parent_id=<parent ID>; name=< name>
The method will return:
- id: the ID of the newly created item
Troubleshooting
When creating documents, if your REST client supports file uploads, make sure the name of the field is “file” (and not “fileUpload” or something else). If your REST client does not support file uploads, you will need to specify additional information in the body:
file=<full pathname>; file_content_type=<mime type>;file_filename=<filename>
Update
This call will update the properties for the specified node ID.
Method: PUT
URL: api/v1/nodes/<id>
Body: name=<name>;description=<description>
This method does not return anything.
Delete
This call will delete an item for the specified node ID.
Method: DELETE
URL: api/v1/nodes/<id>
This method does not return anything.
Volumes
This resource can be used to access a root volume based on its subtype as opposed to is node ID (which can differ across Content Server instances). Some examples of a root volume include the Enterprise Workspace (141) and the current users Personal Workspace (142).
Get
This call will get metadata for the specified subtype.
Method: GET
URL: api/v1/volumes/<subtype>
See the Nodes - Get section for the return values and additional information.
Browse
This call will return information about the children for the specified subtype.
Method: GET
URL: api/v1/volumes/<id>/nodes
See the Nodes - Browse section for the return values and additional information.
Versions
This sub-resource can be used to work with document versions.
Get
This will get the metadata for all versions of a document.
Method: Get
URL: api/v1/nodes/<id>/versions
It can also be used to return metadata for a specific version.
Method: Get
URL: api/v1/nodes/<id>/versions/<version number>
The return values may include:
- data: property values
- definitions: definitions for each property value
Get Content
This will get the content for the specified version.
Method: GET
URL: api/v1/nodes/<id>/versions/<version number>/content
It can also be used to get the content for the current version.
Method: GET
URL: api/v1/nodes/<id>/content
Troubleshooting
If the filename is not resolved properly, you may need to specify it after content in the URL line.
api/v1/nodes/<id>/content/<filename>
Add Version
This will add a new version to the specified document.
Method: POST
URL: api/v1/nodes/<id>/versions
Body: name=<name>
Troubleshooting
If your REST client supports file uploads, make sure the name of the field is “file” (and not “fileUpload” or something else). If your REST client does not support file uploads, you will need to specify additional information in the body:
file=<full pathname>; file_content_type=<mime type>;file_filename=<filename>
Delete Version
This will delete a version for the specified node ID and version number.
Method: DELETE
URL: api/v1/nodes/<id>/versions/<version number>
This method does not return anything.
Update Version
This method will update metadata for the specified nodeID and version number.
Method: PUT
URL: api/v1/nodes/<id>/versions/<version number>
Body: description=<description>
This method does not return anything.
Extending the REST API
This section assumes you already have an existing and working LLNode. This section will also divide the process of exposing an LLNode into smaller steps for better understanding easier debugging.
Common Properties
Every LLNode has a common set of properties (name, description, create date, etc.).
- Follow the steps in Extending csNode - Common Properties in the CSNode Quick Start Guide.
You should now be able to retrieve common metadata about your node from a REST client using the GET method:
/api/v1/nodes/<id>
Custom Properties
You can skip this section if your LLNode does not have subtype specific properties.
- Follow the steps in Extending csNode - Custom Properties in the CSNode Quick Start Guide.
You should now be able to retrieve common and custom properties from a REST client using the GET method:
api/v1/nodes/<id>
Common Actions
Your LLNode should be able to use several pre-defined actions, eliminating the need to write any code.
- Follow the steps in Extending csNode - Common Actions in the CSNode Quick Start Guide.
You should now be able to perform these actions against your node from a REST client. Consult the REST API documentation for the syntax of these actions.
Modifying Actions
You can skip this section if your LLNode does not have any custom properties.
- Follow the steps in Extending csNode - Modifying Actions in the CSNode Quick Start Guide.
You should now be able to perform these actions against your node from a REST client. Consult the REST API documentation for the syntax for these actions.
Custom Actions
You can skip this section if your LLNode does not have any custom functionality.
- Follow the steps in Extending csNode - Custom Actions in the CSNode Quick Start Guide.
- Orphan RESTAPI:Root:RESTAPIMap into your ospace and give it a name.
- Overwrite and run the SetMap function (see Appendix A).
- Build your ospace and restart Builder (may not be required in the Content Server IDE).
You should now be able to perform this action against your node via a REST client.
Troubleshooting
Check that the action has been registered properly:
RESTAPI:Subsystems:RestAPISubsystem:.fMappings
Set a breakpoint in the REST API to see what is being sent in as parameters:
RESTAPI:Root:RestAPI.Dispatch
Roles
You can skip this section if your LLNode does not have any shared functionality across multiple subtypes.
- Follow the steps in Extending csNode - Roles in the CSNode Quick Start Guide.
- Orphan RESTAPI:Root:RESTAPIMap into your ospace (if you haven't already done so) and give it a name.
- Overwrite and run the SetMap function (see Appendix A).
- Build your ospace and restart Builder (may not be required in the Content Server IDE).
You should now be able to perform these actions against your node via a REST client.
Troubleshooting
Check that the actions were registered properly:
RESTAPI:Subsystems:RestAPISubsystem:<temp>.fMappings
Set a breakpoint in the REST API to see what is being sent in as parameters:
RESTAPI:Root:RestAPI.Dispatch