Basic tasks

The Content Hub ONE Client SDK lets you perform various tasks. Before you begin, ensure you understand the basics of working with the SDK.

Create a client

To create a client, use the following code:


var credentials = new ClientCredentialsScheme("<client_id>", "<client_secret>");
var client = ContentHubOneClientFactory.Create(credentials);

Once you have created a client, you can perform any of the following operations.

Get a single content type

To get a single content type, use the following code:

var contentType = await client.ContentTypes.SingleAsync("<content_type_id>");

Get content items of a specific definition

To get content items of a specific definition, use the following code:

var contentItems =
  await _client.ContentItems.GetAsync(
    new ContentItemSearchRequest()
      .WithFieldQuery(
        ContentItemSearchField.ContentType,
        Equality.Equals,
        "<content_type_id>"));

Create, update, and delete content types

To create, update, and delete content types, use the following code:

// Create a content type
var culture = new CultureInfo("en-US");
var contentType = new ContentType
{
  Id = "<content_type_id>",
  Name = new Dictionary<CultureInfo, string> { { culture, "<content_type_name>" } },
  Fields = new List <ContentTypeField>
  {
    new(
      "title",
      new Dictionary <CultureInfo, string>
      {
        { culture, "Title" }
      }),
    new(
      "related",
      new Dictionary <CultureInfo, string>
      {
        { culture, "Related" }
      },
      FieldType.Reference)
  }
};

var newContentType = await _client.ContentTypes.CreateAsync(contentType);

// Update an existing content type
newContentType.Fields.Add(
  new ContentTypeField("body",
    new Dictionary <CultureInfo, string> { { culture, "Body" } },
    FieldType.LongText));

await _client.ContentTypes.UpdateAsync(newContentType);

// Delete a content type
await _client.ContentTypes.DeleteAsync(newContentType.Id);

Create, update, and delete content items

To create, update, and delete content items, use the following code:

// Create a content item
var contentItem = new ContentItem
{
  Id = "MyContentItem",
  Name = "MyContentItem",
  Fields = new Dictionary<string, BaseField>
  {
    {
      "title", new ShortTextField("Hello, world!")
    }
  }
};

var newContentItem = await _client.ContentItems.CreateAsync("<content_type_id>", contentItem);

// Update an existing content item
newContentItem.Fields.Add("body", new LongTextField("Lorem ipsum dolor sit amet."));

await _client.ContentItems.UpdateAsync(newContentItem);

// Delete a content item
await _client.ContentItems.DeleteAsync(newContentItem.Id);
If you have suggestions for improving this article, let us know!