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

Catalog entry associations

Recommended reading 

This topic describes how to work with RESTful operations for catalog entry associations 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 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

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/entries/{entry code}/associations").Result.Content.ReadAsStringAsync().Result

XML response type

Get a specific entry association

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

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/entries/{entry code}/associations/{association name}").Result.Content.ReadAsStringAsync().Result

XML response types

Create entry association

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

JSON response type

C# code sample

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

Update entry association

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

JSON response type

C# code sample

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

Delete entry association

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

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/entries/{entry code}/associations/{association name}").Result.Content.ReadAsStringAsync().Result

XML response type

Related topics

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

Last updated: Oct 20, 2016

Recommended reading