---
title: "Create a product collection relationship"
description: "Create a relationship between a product and a collection."
doc_type: openapi
doc_category: openapi
doc_version: v20270301
source_url:
  html: 'https://developer.shopline.com/docs/admin-rest-api/product/collection-relationship/create-a-product-collection-relationship'
  md: 'https://developer.shopline.com/docs/admin-rest-api/product/collection-relationship/create-a-product-collection-relationship.md'
---
# Create a product collection relationship

Create a relationship between a product and a collection.

- **Base URL:** `https://{handle}.myshopline.com/admin/openapi`
- **Required Scopes:** `write_products`
- **API Version:** v20270301
- **API Type:** Admin
- **API Protocol:** RESTful

## Endpoint

```http
POST /products/collects.json
```

## Base URL

* `https://{handle}.myshopline.com/admin/openapi`

  * `{handle}`: `handle` : The store's unique identifier, which is the prefix of the store's domain name. For example, if a store's domain name is `open001.myshopline.com` , the store handle is `open001` .

## Required Permissions

* `write_products`

## Request

### Request Headers

* `Content-Type`

  string (required)

  The field must be set to the fixed value `application/json; charset=utf-8`.

* `Authorization`

  string (required)

   The access token for the API resource. Refer to [App authorization](https://developer.shopline.com/docs/apps/api-instructions-for-use/app-authorization.md?lang=en) to obtain the access token, and then pass the obtained token in the Bearer format. 

### Request Body

* `collect`

  object

  The relationship between a product and a collection. 

  * `collection_id`

    string

    The unique identifier for the collection.
    <br/>Maximum length: 64

  * `product_id`

    string

    The unique identifier for the product.
    <br/>Maximum length: 64

## Response

### Status Codes

* `200`

  For the complete list of codes and messages, see [Http status code](https://developer.shopline.com/docs/apps/api-instructions-for-use/http-status-code.md?lang=en).

* `201`

  

* `401`

  

* `429`

  

### Response Headers

* `traceId`

  A globally unique identifier for the request. It is used to track the request flow throughout the system, allowing for easy location and debugging when issues arise.

### Response Body

#### 200

* `collect`

  object

  The relationship between a product and a collection. 

  * `collection_id`

    string

    The unique identifier for the collection.

  * `created_at`

    string

    The date and time when the relationship was created. Format: [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html).

  * `id`

    long

    The unique identifier for the relationship.

  * `product_id`

    string

    The unique identifier for the product.

  * `product_priority`

    long

    The priority of the product within its collection. A smaller numerical value indicates a higher priority.

  * `sort_value`

    string

    The sorting value of the product in its collection. Constructed by left-padding the `product_priority` value with zeros to reach a total length of 20 characters.

  * `updated_at`

    string

    The date and time when the relationship was last updated. Format: [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html).


#### 201

* `errors`

  string

  Error message. 


#### 401

* `errors`

  string

  Error message. 


#### 429

* `errors`

  string

  Error message. 


## OpenAPI Definition

```json
{
  "tags": [
    "Create a product collection relationship"
  ],
  "description": "Create a relationship between a product and a collection.",
  "externalDocs": {
    "description": "Permission point used by the interface is `write_products` , For more information about the use of permission points, see",
    "url": "ec20/3cv5d7wpfgr6a8z5/xabczf5442284vkq?lang=en",
    "errorTableDescription": ""
  },
  "operationId": "Tvz7cBoA",
  "parameters": [
    {
      "name": "Content-Type",
      "in": "header",
      "description": "The field must be set to the fixed value `application/json; charset=utf-8`.",
      "required": true,
      "schema": {
        "name": "Content-Type",
        "type": "string",
        "example": "application/json; charset=utf-8"
      }
    },
    {
      "name": "Authorization",
      "in": "header",
      "description": " The access token for the API resource. Refer to [App authorization](https://developer.shopline.com/docs/apps/api-instructions-for-use/app-authorization.md?lang=en) to obtain the access token, and then pass the obtained token in the Bearer format. ",
      "required": true,
      "style": "string",
      "schema": {
        "name": "Authorization",
        "description": " The access token for the API resource. Refer to [App authorization](https://developer.shopline.com/docs/apps/api-instructions-for-use/app-authorization.md?lang=en) to obtain the access token, and then pass the obtained token in the Bearer format. ",
        "type": "string",
        "example": "Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6MCwiYXBwS2V5IjoiNzU2ZjI1NWE2NjdlZTcwNTk1MzM0ZjVjYzk4NzU5MzBmN2E3NGZjMSIsImV4cCI6MTg3OTQ4MjA3NiwiaXNzIjoieXNvdWwiLCJzZWxsZXJJZCI6IjIwMDAyMzQ4ODAiLCJzdG9yZUlkIjoiMTY3MjM2OTcyOTYwNiIsInRpbWVzdGFtcCI6MTc4NDc4NzY3NjY2MSwidmVyc2lvbiI6IlYyIn0.3ZzbGAH4cLU1QR2VPEvMOQInUDvus-C4amkINSQIPuNVlXsFKj0sAt1c0KnUy9MWUOFV9cHlkf7J90r2y1FzpA"
      },
      "example": "Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6MCwiYXBwS2V5IjoiNzU2ZjI1NWE2NjdlZTcwNTk1MzM0ZjVjYzk4NzU5MzBmN2E3NGZjMSIsImV4cCI6MTg3OTQ4MjA3NiwiaXNzIjoieXNvdWwiLCJzZWxsZXJJZCI6IjIwMDAyMzQ4ODAiLCJzdG9yZUlkIjoiMTY3MjM2OTcyOTYwNiIsInRpbWVzdGFtcCI6MTc4NDc4NzY3NjY2MSwidmVyc2lvbiI6IlYyIn0.3ZzbGAH4cLU1QR2VPEvMOQInUDvus-C4amkINSQIPuNVlXsFKj0sAt1c0KnUy9MWUOFV9cHlkf7J90r2y1FzpA"
    }
  ],
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "name": "body",
          "description": "body position parameter",
          "type": "object",
          "properties": {
            "collect": {
              "name": "collect",
              "description": "The relationship between a product and a collection. ",
              "type": "object",
              "properties": {
                "collection_id": {
                  "name": "collection_id",
                  "description": "The unique identifier for the collection.\n<br/>Maximum length: 64",
                  "type": "string",
                  "example": "12249026592161154694000283"
                },
                "product_id": {
                  "name": "product_id",
                  "description": "The unique identifier for the product.\n<br/>Maximum length: 64",
                  "type": "string",
                  "example": "16057039432335097907370282"
                }
              },
              "required": [
                "collection_id",
                "product_id"
              ],
              "example": {
                "collection_id": "12249026592161154694000283",
                "product_id": "16057039432335097907370282"
              }
            }
          },
          "required": [
            "collect"
          ],
          "example": {
            "collect": {
              "collection_id": "12249026592161154694000283",
              "product_id": "16057039432335097907370282"
            }
          }
        },
        "examples": {
          "Create a product collection relationship": {
            "description": "Create a product collection relationship.",
            "value": {
              "collect": {
                "collection_id": "12253922844193351322550282",
                "product_id": "16057039432335097907370282"
              }
            }
          }
        }
      }
    },
    "required": true
  },
  "responses": {
    "200": {
      "description": "For the complete list of codes and messages, see [Http status code](https://developer.shopline.com/docs/apps/api-instructions-for-use/http-status-code.md?lang=en).",
      "headers": {
        "traceId": {
          "description": "A globally unique identifier for the request. It is used to track the request flow throughout the system, allowing for easy location and debugging when issues arise."
        }
      },
      "content": {
        "application/json": {
          "schema": {
            "name": "body",
            "type": "object",
            "properties": {
              "collect": {
                "name": "collect",
                "description": "The relationship between a product and a collection. ",
                "type": "object",
                "properties": {
                  "collection_id": {
                    "name": "collection_id",
                    "description": "The unique identifier for the collection.",
                    "type": "string",
                    "example": "12249026592161154694000282"
                  },
                  "created_at": {
                    "name": "created_at",
                    "description": "The date and time when the relationship was created. Format: [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html).",
                    "type": "string",
                    "example": "2025-03-06T02:20:26+08:00"
                  },
                  "id": {
                    "name": "id",
                    "description": "The unique identifier for the relationship.",
                    "type": "long",
                    "example": 5704511242397819000
                  },
                  "product_id": {
                    "name": "product_id",
                    "description": "The unique identifier for the product.",
                    "type": "string",
                    "example": "16057039432335097907370282"
                  },
                  "product_priority": {
                    "name": "product_priority",
                    "description": "The priority of the product within its collection. A smaller numerical value indicates a higher priority.",
                    "type": "long",
                    "example": 10000000000000
                  },
                  "sort_value": {
                    "name": "sort_value",
                    "description": "The sorting value of the product in its collection. Constructed by left-padding the `product_priority` value with zeros to reach a total length of 20 characters.",
                    "type": "string",
                    "example": "00000010000000000000"
                  },
                  "updated_at": {
                    "name": "updated_at",
                    "description": "The date and time when the relationship was last updated. Format: [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html).",
                    "type": "string",
                    "example": "2025-03-06T02:20:26+08:00"
                  }
                },
                "example": {
                  "collection_id": "12249026592161154694000282",
                  "created_at": "2025-03-06T02:20:26+08:00",
                  "id": 5704511242397819000,
                  "product_id": "16057039432335097907370282",
                  "product_priority": 10000000000000,
                  "sort_value": "00000010000000000000",
                  "updated_at": "2025-03-06T02:20:26+08:00"
                }
              }
            },
            "example": {
              "collect": {
                "id": 5704511242397819000,
                "product_id": "16057039432335097907370282",
                "product_priority": 10000000000000,
                "sort_value": "00000010000000000000",
                "updated_at": "2025-03-06T02:20:26+08:00",
                "collection_id": "12249026592161154694000282",
                "created_at": "2025-03-06T02:20:26+08:00"
              }
            }
          }
        }
      }
    },
    "201": {
      "headers": {
        "traceId": {
          "description": "A globally unique identifier for the request. It is used to track the request flow throughout the system, allowing for easy location and debugging when issues arise."
        }
      },
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "errors": {
                "name": "errors",
                "description": "Error message. ",
                "type": "string"
              }
            },
            "required": [
              "errors"
            ]
          },
          "examples": {
            "Create a product collection relationship": {
              "description": "Create a product collection relationship.",
              "value": {
                "collect": {
                  "updated_at": "2022-12-07T00:17:55+08:00",
                  "collection_id": "12253922844193351322550282",
                  "created_at": "2022-12-07T00:17:55+08:00",
                  "id": 5704511242397819000,
                  "product_id": "16057039432335097907370282",
                  "product_priority": 10000000000000,
                  "sort_value": "00000010000000000000"
                }
              }
            }
          }
        }
      }
    },
    "401": {
      "headers": {
        "traceId": {
          "description": "A globally unique identifier for the request. It is used to track the request flow throughout the system, allowing for easy location and debugging when issues arise."
        }
      },
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "errors": {
                "description": "Error message. ",
                "type": "string"
              }
            },
            "required": [
              "errors"
            ]
          }
        }
      }
    },
    "429": {
      "headers": {
        "traceId": {
          "description": "A globally unique identifier for the request. It is used to track the request flow throughout the system, allowing for easy location and debugging when issues arise."
        }
      },
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "errors": {
                "description": "Error message. ",
                "type": "string"
              }
            },
            "required": [
              "errors"
            ]
          }
        }
      }
    }
  },
  "security": [
    {
      "oauth2": []
    }
  ],
  "method": "post",
  "path": "/products/collects.json",
  "servers": [
    {
      "url": "https://{handle}.myshopline.com/admin/openapi",
      "variables": {
        "handle": {
          "default": "openapiceshidianpu",
          "description": "`handle` : The store's unique identifier, which is the prefix of the store's domain name. For example, if a store's domain name is `open001.myshopline.com` , the store handle is `open001` ."
        }
      }
    }
  ],
  "info": {
    "title": "Create a product collection relationship",
    "version": "v20270301"
  },
  "authIndexes": [
    "write_products"
  ]
}
```