HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityDoc feedbackLog In

Catalog entry associations

Describes how to work with RESTful operations for catalog entry associations in the Optimizely Service API.

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 EntryAssociation
  {
    public int SortOrder { get; set; }
    public string Type { get; set; }
    public string CatalogEntryCode { get; set; }
    public ResourceLink CatalogEntry { get; set; }
  }
[Serializable]
public class Association
  {
    public int SortOrder { get; set; }
    public string Name { get; set; }
    public string CatalogEntryCode { get; set; }
    public string Description { get; set; }
    public List<EntryAssociation> EntryAssociations { get; set; }
  }

Get all entry associations

get/episerverapi/commerce/entries/{entryCode}/associations

JSON response type

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

XML response type

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));       
var result = client.GetAsync("/episerverapi/commerce/entries/{entry code}/associations").Result.Content.ReadAsStringAsync().Result

Response

<ArrayOfAssociation xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Association>
    <SortOrder>0</SortOrder>
    <Name>CrossSell</Name>
    <CatalogEntryCode>Movies-Kids-Jumanji-BluRay</CatalogEntryCode>
    <Description>Related Product</Description>
    <EntryAssociations>
      <EntryAssociation>
        <SortOrder>807</SortOrder>
        <Type>Default</Type>
        <CatalogEntryCode>Movies-Animation-SnowWhite-BluRay</CatalogEntryCode>
        <Entry>
          <Title>Movies-Animation-SnowWhite-BluRay</Title>
          <Type>CatalogEntry</Type>
          <Href>/episerverapi/commerce/entries/Movies-Animation-SnowWhite-BluRay</Href>
        </Entry>
      </EntryAssociation>
      <EntryAssociation>
        <SortOrder>807</SortOrder>
        <Type>Default</Type>
        <CatalogEntryCode>Movies-Horror-ElmStreet-Download</CatalogEntryCode>
        <Entry>
          <Title>Movies-Horror-ElmStreet-Download</Title>
          <Type>CatalogEntry</Type>
          <Href>/episerverapi/commerce/entries/Movies-Horror-ElmStreet-Download</Href>
        </Entry>
      </EntryAssociation>
    </EntryAssociations>
  </Association>
  <Association>
    <SortOrder>0</SortOrder>
    <Name>Default</Name>
    <CatalogEntryCode>Movies-Kids-Jumanji-BluRay</CatalogEntryCode>
    <Description>Related Product</Description>
    <EntryAssociations>
      <EntryAssociation>
        <SortOrder>96</SortOrder>
        <Type>Default</Type>
        <CatalogEntryCode>Movies-Animation-SimpsonsMovie-OnDemand</CatalogEntryCode>
        <Entry>
          <Title>Movies-Animation-SimpsonsMovie-OnDemand</Title>
          <Type>CatalogEntry</Type>
          <Href>/episerverapi/commerce/entries/Movies-Animation-SimpsonsMovie-OnDemand</Href>
        </Entry>
      </EntryAssociation>
      <EntryAssociation>
        <SortOrder>96</SortOrder>
        <Type>Default</Type>
        <CatalogEntryCode>Movies-Drama-CityGod-Download</CatalogEntryCode>
        <Entry>
          <Title>Movies-Drama-CityGod-Download</Title>
          <Type>CatalogEntry</Type>
          <Href>/episerverapi/commerce/entries/Movies-Drama-CityGod-Download</Href>
        </Entry>
      </EntryAssociation>
    </EntryAssociations>
  </Association>
</ArrayOfAssociation>

Get a specific entry association

get/episerverapi/commerce/entries/{entryCode}/associations/{name}

JSON response type

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

XML response types

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));       
var result = client.GetAsync("/episerverapi/commerce/entries/{entry code}/associations/{association name}").Result.Content.ReadAsStringAsync().Result

Response

<Association xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SortOrder>1</SortOrder>
  <Name>UpSell</Name>
  <CatalogEntryCode>Movies-Kids-Jumanji-BluRay</CatalogEntryCode>
  <Description>Description Created</Description>
  <EntryAssociations>
    <EntryAssociation>
      <SortOrder>109</SortOrder>
      <Type>Default</Type>
      <CatalogEntryCode>Movies-Action-Inception-Download</CatalogEntryCode>
      <CatalogEntry>
        <Title>Movies-Action-Inception-Download</Title>
        <Type>CatalogEntry</Type>
        <Href>/episerverapi/commerce/entries/Movies-Action-Inception-Download</Href>
      </CatalogEntry>
    </EntryAssociation>
    <EntryAssociation>
      <SortOrder>109</SortOrder>
      <Type>Default</Type>
      <CatalogEntryCode>Movies-Documentary-ManOnWire-BluRay</CatalogEntryCode>
      <CatalogEntry>
        <Title>Movies-Documentary-ManOnWire-BluRay</Title>
        <Type>CatalogEntry</Type>
        <Href>/episerverapi/commerce/entries/Movies-Documentary-ManOnWire-BluRay</Href>
      </CatalogEntry>
    </EntryAssociation>
  </EntryAssociations>
</Association>

Create entry association

post/episerverapi/commerce/entries/{entryCode}/associations

JSON response type

var model = new Association()
  {
    CatalogEntryCode = "Movies-Kids-Jumanji-BluRay",
    Description = "Description Created",
    Name = "Test",
    SortOrder = 1,
    EntryAssociations = new List<EntryAssociation>()
      {
        new EntryAssociation()
          {
            CatalogEntryCode = "Movies-Kids-IceAge-BluRay",
            SortOrder = 1,
            Type = "Default"
          }
      }
  };

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/entries/{entry code}/associations", 
  new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result

XML response type

var model = new Association()
  {
    CatalogEntryCode = "Movies-Kids-Jumanji-BluRay",
    Description = "Description Created",
    Name = "Test",
    SortOrder = 1,
    EntryAssociations = new List<EntryAssociation>()
      {
        new EntryAssociation()
          {
            CatalogEntryCode = "Movies-Kids-IceAge-BluRay",
            SortOrder = 1,
            Type = "Default"
          }
      }
  };
var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
var serializer = new XmlSerializer(typeof(Association));
var xml = String.Empty;
using (var ms = new MemoryStream())
  {
    serializer.Serialize(ms, model);
    xml = Encoding.Default.GetString(ms.ToArray());
  } 
var result = client.PostAsync("/episerverapi/commerce/entries/{entry code}/associations", 
  new StringContent(xml, Encoding.UTF8, "text/xml")).Result.Content.ReadAsStringAsync().Result

Response

<Association xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SortOrder>1</SortOrder>
  <Name>Test</Name>
  <CatalogEntryCode>Movies-Kids-Jumanji-BluRay</CatalogEntryCode>
  <Description>Description Created</Description>
  <EntryAssociations>
    <EntryAssociation>
      <SortOrder>109</SortOrder>
      <Type>Default</Type>
      <CatalogEntryCode>Movies-Kids-IceAge-BluRay</CatalogEntryCode>
    </EntryAssociation>
  </EntryAssociations>
</Association>

Update entry association

put/episerverapi/commerce/entries/{entryCode}/associations/{name}

JSON response type

var model = new Association()
  {
    CatalogEntryCode = "Movies-Kids-Jumanji-BluRay",
    Description = "Description Created",
    Name = "Test",
    SortOrder = 1,
    EntryAssociations = new List()
      {
        new EntryAssociation()
          {
            CatalogEntryCode = "Movies-Kids-IceAge-BluRay",
            SortOrder = 1,
            Type = "Default"
          }
      }
  };

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/entries/{entry code}/associations/{association name}", 
  new StringContent(json, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result

XML response type

var model = new Association()
  {
    CatalogEntryCode = "Movies-Kids-Jumanji-BluRay",
    Description = "Description Created",
    Name = "Test",
    SortOrder = 1,
    EntryAssociations = new List()
      {
        new EntryAssociation()
          {
            CatalogEntryCode = "Movies-Kids-IceAge-BluRay",
            SortOrder = 1,
            Type = "Default"
          }
      }
  };
var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
var serializer = new XmlSerializer(typeof(Association));
var xml = String.Empty;
using (var ms = new MemoryStream())
  {
    serializer.Serialize(ms, model);
    xml = Encoding.Default.GetString(ms.ToArray());
  }   
var result = client.PutAsync("/episerverapi/commerce/entries/{entry code}/associations/{association name}", 
  new StringContent(xml, Encoding.UTF8, "text/xml")).Result.Content.ReadAsStringAsync().Result

Response

204 No Content

Delete entry association

delete/episerverapi/commerce/entries/{entryCode}/associations/{name}

JSON response type

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

XML response type

var client = new HttpClient()
  {
    BaseAddress = new Uri(ConfigurationManager.AppSettings["integrationUrl"])
  };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));   
var result = client.DeleteAsync("/episerverapi/commerce/entries/{entry code}/associations/{association name}").Result.Content.ReadAsStringAsync().Result

Response

<Association xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SortOrder>1</SortOrder>
  <Name>Test</Name>
  <CatalogEntryCode>Movies-Kids-Jumanji-BluRay</CatalogEntryCode>
  <Description>Description Created</Description>
  <EntryAssociations>
    <EntryAssociation>
      <SortOrder>109</SortOrder>
      <Type>Default</Type>
      <CatalogEntryCode>Movies-Kids-IceAge-BluRay</CatalogEntryCode>
    </EntryAssociation>
  </EntryAssociations>
</Association>