Datasource client
The SDK provides a Datasource client to perform CRUD operations on datasources, also called option lists.
The client variable in the following code examples refers to the ContentHubClient instance. When using the JavaScript SDK, the variable name can be chosen freely, but is also called client at instantiation in the documentation.
Get datasources
A datasource can be retrieved by name:
This returns an IOptionList object. However, it is required to downcast it to the right type of datasource in one of the following ways.
The Type property on IOptionList can be used to identify the correct datasource type at runtime.
Create datasources
To create a hierarchical datasource, an instance needs be created by the factory first. Afterwards, the instance can be saved using the client. The datasource can be used for media types, where every type of media can have more sub-values.
In this example, 'mp4' is added as a subtype of a video media type.
Update datasources
In the following example, a flat colors datasource is extended with the color red:
Delete datasources
In the following example, the Name datasource is deleted: