Skip to main content

Create a Relationship between a Product with one or more Products

POST 

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

  • You can associate a product with up to 2000 other products.
  • You do not need to attach a custom relationship to products beforehand, this will be done automatically by this endpoint.
  • This is a partial update, so if you make a request to this endpoint multiple times with different products in each request, they will not be overwritten but will be appended to the related products list.

If you want to remove a relationship between products, see Delete a Relationship between a product with one or more products.

Prerequisites

  • A Custom Relationship has been created, see create a Custom Relationship.
  • A Product has been created for the relationship to be based from.
  • One or many Product have been created for the product to relate to.

Request

Path Parameters

    productID stringrequired

    A unique identifier for the product.

    customRelationshipSlug stringrequired

    A custom relationship slug.

Body

    data object[]required
  • Array [
  • idstringrequired

    The ID of the product you want to relate.

    typestringrequired

    This represents the type of resource being returned. Always product.

    Possible values: [product]

    attributes object
    sort_orderintegernullable

    The order in which the product to product 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
  • ]

Responses

Returns information related to associated products.

Schema
    meta object
    associated_productsstring[]

    A list of product IDs that have been successfully associated with this custom relationship.

    Example: ["68c48149-0e94-4ef2-93d5-8d5f3774980a","ab4826d1-4a5a-4951-a2a5-98058899f891"]
    products_not_associated object[]

    A list of products that could not be associated, including the reasons why.

  • Array [
  • IDstring

    The ID of the product that could not be associated.

    Example: 97b7fac2-91dd-4755-81b0-bdffe8e7eabd
    Detailsstring

    Details about why the product could not be associated.

    Example: could not find product
  • ]
  • ownerstring

    The owner of the resource.

    Example: store
    timestamps object
    created_atstring<date-time>

    The date and time the resource was created.

    Example: 2024-08-08T09:29:08.295Z
    updated_atstring<date-time>

    The date and time the resource was last updated.

    Example: 2024-08-08T09:29:08.295Z

Authorization: http

name: bearerAuthtype: httpscheme: bearer
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://euwest.api.elasticpath.com/pcm/products/:productID/custom-relationships/:customRelationshipSlug");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer <token>");
var content = new StringContent("{\n \"data\": [\n {\n \"id\": \"string\",\n \"type\": \"product\",\n \"attributes\": {\n \"sort_order\": 5\n }\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
Parameters
— pathrequired
— pathrequired
Body
{
  "data": [
    {
      "id": "string",
      "type": "product",
      "attributes": {
        "sort_order": 5
      }
    }
  ]
}
ResponseClear

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