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

Catalog nodes

Recommended reading 

This topic describes how to work with RESTful operations for catalog nodes in the Optimizely Service API.

In this topic

Example models

[Serializable]
public class NameValue
  {
    public string Name { get; set; }
    public string Value { get; set; }
  }
[Serializable]
public class ResourceLink
  {
    public string Title { get; set; }
    public string Type { get; set; }
    public string Href { get; set; }
    public List<NameValue> Properties { get; set; }
  }	

[Serializable]
public class SeoInfo
  {
    public string Title { get; set; }
    public string Uri { get; set; }
    public string UriSegment { get; set; }
    public string Description { get; set; }
    public string Keywords { get; set; }
    public string LanguageCode { get; set; }
  }
		
[Serializable]
public class MetaFieldData
  {
    public string Language { get; set; }
    public string Value { get; set; }
  }

[Serializable]
public class MetaFieldProperty
  {
    public string Name { get; set; }
    public string Type { get; set; }
    public List<MetaFieldData> Data { get; set; }
  }

[Serializable]
public class Node
  {
    public Node()
      {
        SeoInformation = new List<SeoInfo>();
        Assets = new List<ResourceLink>();
        MetaFields = new List<MetaFieldProperty>();
        Children = new List<ResourceLink>();
        Entries = new List<ResourceLink>();
      }

    public string Code { get; set; }
    public string ParentNodeCode { get; set; }
    public string Name { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public bool IsActive { get; set; }
    public string MetaClass { get; set; }
    public string Catalog { get; set; }
    public int SortOrder { get; set; }
    public ResourceLink ParentNode { get; set; }
    public List<MetaFieldProperty> MetaFields { get; set; }
    public List<SeoInfo> SeoInformation { get; set; }
    public List<ResourceLink> Assets { get; set; }
    public List<ResourceLink> Children { get; set; }
    public List<ResourceLink> Entries { get; set; }
  }

Published catalog nodes

Get all nodes

By default this method gets all languages for the catalog nodes and entries. If you want only one specific language, use the Accept-Language header.

get/episerverapi/commerce/catalog/{catalogName}/nodes

JSON response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);		
var result = client.GetAsync("/episerverapi/commerce/catalog/{catalogName}/nodes").Result.Content.ReadAsStringAsync().Result

XML response type

Get a specific node

By default this method gets all languages for the catalog nodes and entries. If you want only one specific language, use the Accept-Language header.

get/episerverapi/commerce/nodes/{nodeCode}

JSON response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);		
var result = client.GetAsync("/episerverapi/commerce/nodes/{node code}").Result.Content.ReadAsStringAsync().Result

XML response type

Create node

post/episerverapi/commerce/nodes

JSON response type

C# code sample

var model = new Node()
  {
    Code = "Node 2",
    Catalog = "Departmental Catalog",
    EndDate = DateTime.UtcNow.AddDays(100),
    IsActive = true,
    MetaClass = "CatalogNodeEx",
    Name = "Test",
    StartDate = DateTime.UtcNow,
    ParentNodeCode = "Departments",
    MetaFields = new List<MetaFieldProperty>()
      {
        new MetaFieldProperty()
          {
            Name = "DisplayName",
            Type = "ShortString",
            Data = new List<MetaFieldData>()
              {
                new MetaFieldData()
                  {
                    Language="en",
                    Value = "DisplayName"
                  }
              }
          }
      },
    SeoInformation = new List<SeoInfo>()
      {
        new SeoInfo()
          {
            Description = "description",
            Keywords="",
            LanguageCode = "en",
            Title = "title",
            Uri = "node 2",
            UriSegment = "node 2"
          }
      }
  };
var json = JsonConvert.SerializeObject(model);
var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);    
var result = client.PostAsync("/episerverapi/commerce/nodes",
  new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result

XML response type

Update node

put/episerverapi/commerce/nodes/{nodeCode}

JSON response type

C# code sample

var model = new Node()
  {
    Code = "Node 2",
    Catalog = "Departmental Catalog",
    EndDate = DateTime.UtcNow.AddDays(100),
    IsActive = true,
    MetaClass = "CatalogNodeEx",
    Name = "Test",
    StartDate = DateTime.UtcNow,
    ParentNodeCode = "Departments",
    MetaFields = new List<MetaFieldProperty>()
      {
        new MetaFieldProperty()
          {
            Name = "DisplayName",
            Type = "ShortString",
            Data = new List<MetaFieldData>()
              {
                new MetaFieldData()
                  {
                    Language="en",
                    Value = "DisplayName"
                  }
              }
          }
      },
    SeoInformation = new List<SeoInfo>()
      {
        new SeoInfo()
          {
            Description = "description",
            Keywords="",
            LanguageCode = "en",
            Title = "title",
            Uri = "node 2",
            UriSegment = "node 2"
          }
      }
  };
var json = JsonConvert.SerializeObject(model);
var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);    
var result = client.PutAsync("/episerverapi/commerce/nodes/{node code}",
  new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result

XML response type

Delete node

delete/episerverapi/commerce/nodes/{nodeCode}

JSON response type

C# code sample

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);		
var result = client.DeleteAsync("/episerverapi/commerce/nodes/{node code}").Result.Content.ReadAsStringAsync().Result

XML response type

Common draft catalog nodes [New in Service API 5.1.0]

By adding new endpoints as listed below, you can get common draft versions of catalog nodes, create new common node drafts, and update or delete existing node drafts.

Get common draft node

get/episerverapi/commerce/nodes/{nodeCode}/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/nodes/Node_1/commondraft/en").Result.Content.ReadAsStringAsync().Result;

XML response type

Create common draft node

Note: The Service API 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/nodes/commondraft/{lang}

JSON response type

C# code sample

var parentNodeCode = "TESTCATALOGTNODE";
var _model = new DraftNode
  {
    Code = "Node 2",
    Catalog = "TESTROOTCATALOG",
    EndDate = DateTime.UtcNow.AddDays(100),
    MetaClass = DefaultNodeMetaClassName,
    Name = "Test",
    StartDate = DateTime.UtcNow,
    ParentNodeCode = parentNodeCode,
    ParentNode = new Models.ResourceLink()
      {
        Title = "TEST CATALOG NODE",
        Type = CatalogContentType.CatalogNode.ToString(),
        Href = $"/episerverapi/commerce/nodes/{parentNodeCode}",
        Properties = new List<Models.NameValue>() 
          {
            new Models.NameValue()
              {
                Name = "Code",
                Value = parentNodeCode
              }
          }
      },
   MetaFields = new List<DraftMetaFieldProperty>
     {
       new DraftMetaFieldProperty
         {
           Name = AnotherMultiLanguageStringMetaFieldName,
           Type = MetaDataType.ShortString.ToString(),
           Data = "Set with lang key EN for en"
         },
       new DraftMetaFieldProperty
         {
            Name = "DisplayName",
            Type = MetaDataType.ShortString.ToString(),
            Data = "DisplayName"
         },
     }
  };
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/nodes/commondraft/en",
  new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result;

XML response type

Update common draft node 

Note: If common draft content is in “Published” state, a new common draft version is created (same behavior as Post common draft). If common draft content is in "DelayedPublish/AwaitingApproval/CheckedIn" state, then updating content is skipped, and a Conflict status code (409) is returned.
put/episerverapi/commerce/nodes/{nodeCode}/commondraft/{lang}

JSON response type

C# code sample

var languageCode = "en";

_model = ServiceLocator.Instance.GetInstance<NodeModelFactory>()
.CreateDraftNodeModel(node, languageCode);
_model.Name = "Put Test";
_model.SeoInformation.Uri = "NewNodeUri";

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/nodes/Node_1/commondraft/{languageCode}",
  new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result;

XML response type

Delete common draft node

delete/episerverapi/commerce/nodes/{nodeCode}/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/nodes/Node_1/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: May 05, 2021

Recommended reading