Loading...
Area: Optimizely Service API
Applies to versions: 1.0 and higher

Catalogs

Recommended reading 

This topic describes how to work with RESTful operations for catalogs in the Optimizely Service API. The Service API supports published versions of catalogs (from version 1.0 and higher), as well as common draft versions of catalogs (from version 5.1.0). 

In this topic

Example models

/// <summary>
/// The catalog base model.
/// </summary>
[Serializable]
public abstract class CatalogBase
  {
    /// <summary>
    /// Gets or sets the end date.
    /// </summary>
    /// <value>
    /// The end date.
    /// </value>
    public DateTime EndDate { get; set; }

    /// <summary>
    /// Gets or sets the start date.
    /// </summary>
    /// <value>
    /// The start date.
    /// </value>
    public DateTime StartDate { get; set; }

    /// <summary>
    /// Gets or sets a value indicating whether this instance is primary.
    /// </summary>
    /// <value>
    /// <c>true</c> if this instance is primary; otherwise, <c>false</c>.
    /// </value>
    public bool IsPrimary { get; set; }

    /// <summary>
    /// Gets or sets the owner.
    /// </summary>
    /// <value>
    /// The owner.
    /// </value>
    public string Owner { get; set; }

    /// <summary>
    /// Gets or sets the sort order.
    /// </summary>
    /// <value>
    /// The sort order.
    /// </value>
    public int SortOrder { get; set; }

    /// <summary>
    /// Gets or sets the name.
    /// </summary>
    /// <value>
    /// The name.
    /// </value>
    public string Name { get; set; }

    /// <summary>
    /// Gets or sets the default currency.
    /// </summary>
    /// <value>
    /// The default currency.
    /// </value>
    public string DefaultCurrency { get; set; }

    /// <summary>
    /// Gets or sets the default language.
    /// </summary>
    /// <value>
    /// The default language.
    /// </value>
    public string DefaultLanguage { get; set; }

    /// <summary>
    /// Gets or sets the weight base.
    /// </summary>
    /// <value>
    /// The weight base.
    /// </value>
    public string WeightBase { get; set; }

    /// <summary>
    /// Gets or sets the length base.
    /// </summary>
    /// <value>
    /// The length base.
    /// </value>
    public string LengthBase { get; set; }
  }

/// <summary>
/// The catalog model.
/// </summary>
[Serializable]
public class Catalog: CatalogBase
  {
    /// <summary>
    /// Gets or sets a value indicating whether this instance is active.
    /// </summary>
    /// <value>
    ///   <c>true</c> if this instance is active; otherwise, <c>false</c>.
    /// </value>
    public bool IsActive { get; set; }

    /// <summary>
    /// Gets or sets the languages.
    /// </summary>
    /// <value>
    /// The languages.
    /// </value>
    public List<CatalogLanguage> Languages { get; set; }

    /// <summary>
    /// Gets or sets the nodes.
    /// </summary>
    /// <value>The nodes.</value>
    public List<ResourceLink> Nodes { get; set; }

    /// <summary>
    /// Gets or sets the entries.
    /// </summary>
    /// <value>
    /// The entries.
    /// </value>
    public List<ResourceLink> Entries { get; set; }
  }

/// <summary>
/// The draft catalog model.
/// </summary>
[Serializable]
public class DraftCatalog : CatalogBase
  {
    /// <summary>
    /// Gets or sets the route segment.
    /// </summary>
    /// <value>The route segment.</value>
    public string RouteSegment { get; set; }
  }

Published catalog version

Get all catalogs

get/episerverapi/commerce/catalogs

JSON response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };

client.DefaultRequestHeaders.Authorization = new AuthorizationHeaderValue("Bearer", token.AccessToken);

var result = client.Get("/episerverapi/commerce/catalogs").Result.Content.ReadAsStringAsync().Result;

XML response type

Get a specific catalog

get/episerverapi/commerce/catalogs/{catalogName}

JSON response type

C# code sample

var client = new HttpClient()
 {
   BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
 };

client.DefaultRequestHeaders.Authorization = new AuthorizationHeaderValue("Bearer", token.AccessToken);

var result = client.Get("/episerverapi/commerce/catalogs/Departmental Catalog").Result.Content.ReadAsStringAsync().Result;

XML response type

Create catalog

post/episerverapi/commerce/catalogs

JSON response type

C# code sample

var model = new Catalog()
  {
    DefaultCurrency = "usd",
    DefaultLanguage = "en",
    EndDate = DateTime.UtcNow.AddYears(1),
    IsActive = true,
    IsPrimary = true,
    Languages = new List<CatalogLanguage>()
      {
        new CatalogLanguage()
          {
            Catalog = "Test Post",
            LanguageCode = "en",
            UriSegment = "Test-Post"
          }
      },
    Name = "Test Post",
    StartDate = DateTime.UtcNow,
    WeightBase = "lbs"
  };                

var json = JsonConvert.SerializeObject(model);
var client = new HttpClient()
 {
   BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
 };
client.DefaultRequestHeaders.Authorization = new AuthorizationHeaderValue("Bearer", token.AccessToken);

var result = client.PostAsync("/episerverapi/commerce/catalogs", new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result;

XML response type

Update catalog

put/episerverapi/commerce/catalogs/{catalogName}

JSON response type

C# code sample

var model = new Catalog()
  {
    DefaultCurrency = "vnd",
    DefaultLanguage = "en",
    EndDate = DateTime.UtcNow.AddYears(1),
    IsActive = true,
    IsPrimary = true,
    Languages = new List<CatalogLanguage>()
      {
        new CatalogLanguage()
          {
            Catalog = "Test Post",
            LanguageCode = "en",
            UriSegment = "Test-Post"
          }
      },
    Name = "Test Post",
    StartDate = DateTime.UtcNow,
    WeightBase = "lbs"
  };                

var json = JsonConvert.SerializeObject(model);
var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
   };
client.DefaultRequestHeaders.Authorization = new AuthorizationHeaderValue("Bearer", token.AccessToken);

var result = client.PutAsync("/episerverapi/commerce/catalogs/Test Post", new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result;

XML response type

Delete catalog

delete/episerverapi/commerce/catalogs/{catalogName}

JSON response type

C# code sample

var client = new HttpClient()
  {
     BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };

client.DefaultRequestHeaders.Authorization = new AuthorizationHeaderValue("Bearer", token.AccessToken);

var result = client.DeleteAsync("/episerverapi/commerce/catalogs/Test Catalog").Result.Content.ReadAsStringAsync().Result;

XML response type

Common draft catalog version [New in 5.1.0]

From version 5.1.0, the Service API supports working with a common draft catalog. By adding endpoints described in the following, you can get common draft catalog versions, create new common drafts, and update or delete existing common draft catalogs.

Get common draft catalog

get/episerverapi/commerce/catalogs/{catalogName}/commondraft/{lang}

JSON response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };

client.DefaultRequestHeaders.Authorization = new AuthorizationHeaderValue("Bearer", token.AccessToken);

var result = client.GetAsync("/episerverapi/commerce/catalogs/Integration Test/commondraft/en").Result.Content.ReadAsStringAsync().Result;

XML response type

Create common draft catalog

Note: Optimizely does not support creating common drafts for non-existing content. You can create a first draft version by using an endpoint for published content (without “commondraft”) and setting IsActive to “false”.

post/episerverapi/commerce/catalogs/commondraft/{lang}

JSON response type

C# code sample

var _model = new DraftCatalog()
  {
    DefaultCurrency = "usd",
    DefaultLanguage = "en",
    EndDate = DateTime.UtcNow.AddYears(1),
    IsPrimary = true,
    Name = "Test Common Draft Catalog Post",
    StartDate = DateTime.UtcNow,
    WeightBase = "lbs",
    LengthBase = "cms",
    RouteSegment = "common_drart_catalog.aspx"
  };

var json = JsonConvert.SerializeObject(_model);
var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthorizationHeaderValue("Bearer", token.AccessToken);

var result = client.PostAsync("/episerverapi/commerce/catalogs/commondraft/en", new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result;

XML response type

Update common draft catalog

Note: If common draft content is in a “Published” state, then a new common draft version is created (same behavior as Post common draft). If a common draft content is in DelayedPublish/AwaitingApproval/CheckedIn state, then content update is skipped, and a Conflict status code (409) is returned.

put/episerverapi/commerce/catalogs/{catalogName}/commondraft/{lang}

JSON response type

C# code sample

ar catalogName = "Integration Test";
var catalogContents = ContentLoader.GetChildren<CatalogContent>(ReferenceConverter.GetRootLink());
var catalogContent = catalogContents.FirstOrDefault(c => c.Name.Equals(catalogName, StringComparison.OrdinalIgnoreCase));
if (catalogContent != null)
  {
    _model = ServiceLocator.Instance.GetInstance<CatalogModelFactory>() .GetDraftCatalog(catalogContent);
    _model.RouteSegment = "New_Route_Segment";
    var json = JsonConvert.SerializeObject(_model);
    var client = new HttpClient()
      {
       	BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
      };
    client.DefaultRequestHeaders.Authorization = new AuthorizationHeaderValue("Bearer", token.AccessToken);
    var result = client.PutAsync($"/episerverapi/commerce/catalogs/{catalogName}/commondraft/en",
      new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result;
  }

XML response type

Delete common draft catalog

delete/episerverapi/commerce/catalogs/{catalogName}/commondraft/{lang}

JSON response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };

client.DefaultRequestHeaders.Authorization = new AuthorizationHeaderValue("Bearer", token.AccessToken);

var result = client.DeleteAsync("/episerverapi/commerce/catalogs/Integration Test/commondraft/en").Result.Content.ReadAsStringAsync().Result;

XML response type

Related topics

Do you find this information helpful? Please log in to provide feedback.

Last updated: Jul 30, 2018

Recommended reading