1. Content Hub ONE Client SDK

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);
const credentials = new ClientCredentialsScheme("<client_id>", "<client_secret>");
const client = ContentHubOneClientFactory.create(
  credentials,
  new ContentHubOneClientOptions({
    apiEnvironment: : ApiEnvironment = {
      apiBasePath: "<api_base>",
      identityAuthority: "<identity_authority>",
      identityAudience: "<identity_audience>",
      mediaUploadBasePath: "<media_path>",
    }
  })
);

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>");
const 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>"));
const 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 a content type
const contentType = new ContentType("<content_type_id>", {
  name: { "en-US": "<content_type_name>" },
  fields: [
    new ContentTypeField("title", {
      name: { "en-US": "Title" },
    }),
    new ContentTypeField("related", {
      name: { "en-US": "Title" },
      type: "Reference",
    }),
  ],
});

const newContentType = await _client.contentTypes.createAsync(contentType);

// Update an existing content type
newContentType?.fields.push(
  new ContentTypeField("body", {
    name: { "en-US": "Body" },
    type: "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);
// Create a content item
const contentItem = new ContentItem("MyContentItem", {
  name: "MyContentItem",
  fields: {
    title: new ShortTextField("Hello, world!"),
  },
});

const newContentItem = await _client.contentItems.createAsync("<content_type_id>", contentItem);

// Update an existing content item
newContentItem!.fields.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!