Skip to main content

Create a custom relationship

POST 

https://euwest.api.elasticpath.com/pcm/custom-relationships

Custom relationships can either be bi-directional or uni-directional.

  • Uni-Directional: By setting bi_directional to false (or omitted from request) a uni-directional custom relationship will be created. Within a uni-directional relationship, if Product A links to Product B, Product B will not link back to Product A. This is ideal when one product (e.g., a base product) recommends another (e.g., an upsell), but the reverse recommendation is unnecessary.

  • Bi-Directional: By setting bi_directional to true a bi-directional custom relationship will be created. Within a bi-directional relationship, if Product A is linked to Product B, Product B will automatically link back to Product A. This bi-directionality ensures a consistent experience, where products always suggest each other as related items.

For more information on use cases, see Custom Relationships.

Custom Relationship slugs must meet the following criteria:

  • be unique
  • be prefixed with CRP_. Product Experience Manager automatically adds the CRP_ prefix if you do not include it.
  • contain A to Z, a to z, 0 to 9, hyphen, underscore, and period. Spaces or other special characters like ^, [], *, and $ are not allowed.

Once a custom relationship has been created, you can then create Product Relationships:

  1. Add the custom relationship to a product. See Attach a custom relationship to a product.
  2. Associate a product to multiple products. See Associate a product with other products under a custom relationship.

Request

Bodyrequired

    data objectrequired
    typestringrequired

    This represents the type of resource object being returned. Always custom-relationship.

    Possible values: [custom-relationship]

    attributes objectrequired
    namestringrequired

    The name of the custom relationship to display to shoppers, such as Kitchen electrics.

    Example: Related Products
    descriptionstring

    A description of the custom relationship.

    Example: A list of related products shown on the PDP.
    slugstringrequired

    A unique slug for the custom relationship. Must match the slug specified in the request path. A slug can contain A to Z, a to z, 0 to 9, hyphen, underscore, and period. Spaces or other special characters like ^, [], *, and $ are not allowed.

    Possible values: Value must match regular expression ^[A-Za-z0-9._-]+$

    Example: CRP_related_products
    sort_orderintegernullable

    The order in which the custom relationship should be displayed in relation to others. A lower value represents a higher priority in the display order. If set to NULL, the sort order will be removed.

    Example: 5
    external_namestringnullable

    The shopper-facing name for the custom relationship. This value will be displayed to shoppers in the store-front, replacing the internal name if present. If set to NULL, the external name will be removed.

    Example: Similar items to consider
    external_descriptionstringnullable

    The shopper-facing description for the custom relationship. This value will be shown to shoppers in the store-front, replacing the internal description if present. If set to NULL, the external description will be removed.

    Example: Check out these similar products that may also meet your needs or match your preferences.
    bi_directionalboolean

    Is this relationship one way or bi-directional true or false. Default is false

    Default value: false

Responses

Returns a created custom relationship with the following attributes.

Schema
    data objectrequired
    idstringrequired

    A unique identifier generated when a custom relationship is created.

    typestringrequired

    This represents the type of resource object being returned. Always custom-relationship.

    Possible values: [custom-relationship]

    attributes objectrequired
    namestringrequired

    The name of the custom relationship to display to shoppers, such as Kitchen electrics.

    Example: Related Products
    descriptionstring

    A description of the custom relationship.

    Example: A list of related products shown on the PDP.
    slugstringrequired

    A unique slug for the custom relationship. Must match the slug specified in the request path. A slug can contain A to Z, a to z, 0 to 9, hyphen, underscore, and period. Spaces or other special characters like ^, [], *, and $ are not allowed.

    Possible values: Value must match regular expression ^[A-Za-z0-9._-]+$

    Example: CRP_related_products
    sort_orderintegernullable

    The order in which the custom relationship should be displayed in relation to others. A lower value represents a higher priority in the display order. If set to NULL, the sort order will be removed.

    Example: 5
    external_namestringnullable

    The shopper-facing name for the custom relationship. This value will be displayed to shoppers in the store-front, replacing the internal name if present. If set to NULL, the external name will be removed.

    Example: Similar items to consider
    external_descriptionstringnullable

    The shopper-facing description for the custom relationship. This value will be shown to shoppers in the store-front, replacing the internal description if present. If set to NULL, the external description will be removed.

    Example: Check out these similar products that may also meet your needs or match your preferences.
    bi_directionalboolean

    Is this relationship one way or bi-directional true or false. Default is false

    Default value: false
    meta objectrequired
    ownerstringrequired

    The owner of the resource.

    Example: store
    timestamps objectrequired
    created_atdate-timerequired

    The date and time the resource is created.

    Example: 2024-01-10T20:16:35.343Z
    updated_atdate-timerequired

    The date and time the resource is updated.

    Example: 2024-01-10T20:16:35.343Z

Authorization: http

name: bearerAuthtype: httpscheme: bearer
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://euwest.api.elasticpath.com/pcm/custom-relationships");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer <token>");
var content = new StringContent("{\n \"data\": {\n \"type\": \"custom-relationship\",\n \"attributes\": {\n \"name\": \"Related Products\",\n \"description\": \"A list of related products shown on the PDP.\",\n \"slug\": \"CRP_related_products\",\n \"sort_order\": 5,\n \"external_name\": \"Similar items to consider\",\n \"external_description\": \"Check out these similar products that may also meet your needs or match your preferences.\",\n \"bi_directional\": false\n }\n }\n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
Request Collapse all
Base URL
https://euwest.api.elasticpath.com
Auth
Body required
{
  "data": {
    "type": "custom-relationship",
    "attributes": {
      "name": "Related Products",
      "description": "A list of related products shown on the PDP.",
      "slug": "CRP_related_products",
      "sort_order": 5,
      "external_name": "Similar items to consider",
      "external_description": "Check out these similar products that may also meet your needs or match your preferences.",
      "bi_directional": false
    }
  }
}
ResponseClear

Click the Send API Request button above and see the response here!

We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies.