Create a custom relationship
POSThttps://euwest.api.elasticpath.com/pcm/custom-relationships
Custom relationships can either be bi-directional or uni-directional.
-
Uni-Directional: By setting
bi_directional
tofalse
(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
totrue
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 theCRP_
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:
- Add the custom relationship to a product. See Attach a custom relationship to a product.
- Associate a product to multiple products. See Associate a product with other products under a custom relationship.
Request
- application/json
Bodyrequired
data objectrequired
Responses
- 201
- 422
- 500
Returns a created custom relationship with the following attributes.
- application/json
- Schema
- Example (auto)
- created-basic-custom-relationship
- created-custom-relationship-external-sort-order
- created-custom-relationship-bi-directional
Schema
data objectrequired
{
"data": {
"id": "string",
"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
},
"meta": {
"owner": "store",
"timestamps": {
"created_at": "2024-01-10T20:16:35.343Z",
"updated_at": "2024-01-10T20:16:35.343Z"
}
}
}
}
Basic
{
"data": {
"id": "f3297ee8-da90-45e9-ae56-a2654aebbdfe",
"type": "custom-relationship",
"attributes": {
"name": "Kitchen electrics",
"description": "Kitchen electric devices",
"slug": "CRP_kitchen_individual_devices",
"bi_directional": false
},
"meta": {
"owner": "store",
"timestamps": {
"created_at": "2024-01-10T20:16:35.343Z",
"updated_at": "2024-01-10T20:16:35.343Z"
}
}
}
}
External name and description, and sort order
{
"data": {
"id": "e390ff7e-efc4-4769-90d2-fceabcc1e2cd",
"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
},
"meta": {
"owner": "store",
"timestamps": {
"created_at": "2024-01-10T20:16:35.343Z",
"updated_at": "2024-01-10T20:16:35.343Z"
}
}
}
}
Bi-Directional
{
"data": {
"id": "e390ff7e-efc4-4769-90d2-fceabcc1e2cd",
"type": "custom-relationship",
"attributes": {
"name": "Related Products",
"description": "A list of related products shown on the PDP",
"slug": "CRP_related_products",
"bi_directional": true
},
"meta": {
"owner": "store",
"timestamps": {
"created_at": "2024-01-10T20:16:35.343Z",
"updated_at": "2024-01-10T20:16:35.343Z"
}
}
}
}
Bad request. The request failed validation.
- application/json
- Schema
- Example (auto)
- failed-validation
Schema
errors undefined[]required
{
"errors": [
{
"status": "500",
"title": "Internal server error",
"detail": "An internal error has occurred.",
"request_id": "00000000-0000-0000-0000-000000000000",
"meta": {
"missing_ids": [
"e7d50bd5-1833-43c0-9848-f9d325b08be8"
]
}
}
]
}
{
"errors": [
{
"title": "Failed Validation",
"status": "422",
"detail": "<XYZ> can not be empty"
}
]
}
Internal server error. There was a system failure in the platform.
- application/json
- Schema
- Example (auto)
- internal-server-error
Schema
errors undefined[]required
{
"errors": [
{
"status": "500",
"title": "Internal server error",
"detail": "An internal error has occurred.",
"request_id": "00000000-0000-0000-0000-000000000000",
"meta": {
"missing_ids": [
"e7d50bd5-1833-43c0-9848-f9d325b08be8"
]
}
}
]
}
{
"errors": [
{
"status": "500",
"title": "Internal Server Error",
"detail": "There was an internal server error, you can report with your request id.",
"request_id": "635da56d-75a1-43cd-b696-7ab119756b3a"
}
]
}
Authorization: http
name: bearerAuthtype: httpscheme: bearer
- csharp
- curl
- dart
- go
- http
- java
- javascript
- kotlin
- c
- nodejs
- objective-c
- ocaml
- php
- powershell
- python
- r
- ruby
- rust
- shell
- swift
- HTTPCLIENT
- RESTSHARP
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());