Create a Relationship between a Product with one or more Products
POSThttps://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
Responses
- 201
- 400
- 403
- 404
- 409
- 422
- 500
Returns information related to associated products.
Schema
meta object
{
"meta": {
"associated_products": [
"68c48149-0e94-4ef2-93d5-8d5f3774980a",
"ab4826d1-4a5a-4951-a2a5-98058899f891"
],
"products_not_associated": [
{
"ID": "97b7fac2-91dd-4755-81b0-bdffe8e7eabd",
"Details": "could not find product"
},
{
"ID": "a0ef3291-2ec1-4d7d-9d6d-1705ae01bb99",
"Details": "product already has 5 custom relationships, cannot associate more as it has reached the limit of 5 custom relationships"
},
{
"ID": "bde79675-4783-40b7-8a7e-ac6df41459c6",
"Details": "product already has 5 custom relationships, cannot associate more as it has reached the limit of 5 custom relationships"
},
{
"ID": "aaddd5f4-a5f8-42e8-be9a-097986f22e58",
"Details": "exceeded maximum allowed associations (2000). Please review and try again"
}
],
"owner": "store",
"timestamps": {
"created_at": "2024-08-08T09:29:08.295Z",
"updated_at": "2024-08-08T09:29:08.295Z"
}
}
}
{
"meta": {
"associated_products": [
"68c48149-0e94-4ef2-93d5-8d5f3774980a",
"ab4826d1-4a5a-4951-a2a5-98058899f891"
],
"products_not_associated": [
{
"ID": "97b7fac2-91dd-4755-81b0-bdffe8e7eabd",
"Details": "could not find product"
},
{
"ID": "a0ef3291-2ec1-4d7d-9d6d-1705ae01bb99",
"Details": "product already has 5 custom relationships, cannot associate more as it has reached the limit of 5 custom relationships"
},
{
"ID": "bde79675-4783-40b7-8a7e-ac6df41459c6",
"Details": "product already has 5 custom relationships, cannot associate more as it has reached the limit of 5 custom relationships"
},
{
"ID": "aaddd5f4-a5f8-42e8-be9a-097986f22e58",
"Details": "product exceeds the maximum limit of associated products (2000). Please review and try again"
}
],
"owner": "store",
"timestamps": {
"created_at": "2024-08-08T09:29:08.295Z",
"updated_at": "2024-08-08T09:29:08.295Z"
}
}
}
Bad request. The request 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": "Bad Request",
"detail": "Could not parse the supplied filter",
"status": "400"
}
]
}
Forbidden
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": "Forbidden",
"status": "403",
"detail": "entity owned by organization"
}
]
}
Bad Request. Not Found.
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": "Not Found",
"status": "404"
}
]
}
Write conflict detected
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": "Conflict",
"status": "409",
"detail": "write conflict detected"
}
]
}
Bad request. The request 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.
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/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());
ResponseClear