---
title: "Data source client"
slug: "data-source-client"
abstract: "Use the Data source client to get, create, update, or delete flat or hierarchical option lists used in Content Hub."
---
# Data source client

The Data source client can be used to perform CRUD operations on data sources, also called option lists.

## Get data sources { .notintoc }

A data source can be retrieved by name:

```csharp
IDataSource result = await MClient.DataSources.GetAsync(<NAME>);

```

This returns an `IDataSource` object. However, we recommend that you downcast it to the correct data source type as follows:

```csharp
IHierarchicalDataSource hierachicalDataSource = await MClient.DataSources.GetAsync(name) as IHierarchicalDataSource;

```

This lets you change the value of the data source.

```csharp
IFlatDataSource flatDataSource = await MClient.DataSources.GetAsync(<NAME>) as IFlatDataSource;

```

> [!note]
> The `Type` property on `IDataSource` identifies the correct data source type at runtime.

## Create data sources { .notintoc }

To create a hierarchical data source, use the factory to create an instance and then save the instance in the data source client.

For example, you can do this for media types, so that each type of media can have multiple subvalues.

In this example, `mp4` is added as a subtype of a video media type.

```csharp
var dataSource = MClient.DataSourceFactory.CreateHierarchicalDataSource("MediaType");
dataSource.Labels.Add(enUs, "Media type");

var video = new HierarchicalDataSourceValue("Video")
{
  Labels = { { enUs, "Video" } }
};

var mp4 = new HierarchicalDataSourceValue("MP4")
{
  Labels = { { enUs, "mp4" } }
};
video.Values.Add(mp4);

var image = new HierarchicalDataSourceValue("Image")
{
  Labels = { { enUs, "Image" } }
};

dataSource.Values.Add(video);
dataSource.Values.Add(image);

await MClient.DataSources.CreateAsync(dataSource);

```

## Update data sources { .notintoc }

In the following example, a flat colors data source is extended with the color red:

```csharp
var dataSource = await MClient.DataSources.GetAsync("Colors") as IFlatDataSource;

var red = new FlatDataSourceValue("Red")
{
  Labels = { { enUs, "Red" } }
};
dataSource.Values.Add(red);

await MClient.DataSources.UpdateAsync(dataSource);

```

## Delete data sources { .notintoc }

In the following example, the *MediaType* data source is deleted:

```csharp
await MClient.DataSources.DeleteAsync("MediaType");

```