# User Collections

The User Collections feature enables storefront users to create, manage, and share collections of products. Users can set collections as either public or private, with the default setting being private. Public collections are accessible to all users, including anonymous ones, via a specific URL, whereas private collections are only accessible to the collection owner.

**Features:**

* **Create Collections:** Users can create new collections and define their visibility status.
* **Manage Collections:** Users can update, rename, or change the visibility status of their collections.
* **Product Management:** Users can add or remove products from their collections.

***

### `POST` Create a Collection

This endpoint allows users to create a new user collection.

**Path:** `https://{commerce_url}/wishlists/user-collections/`

**Body Parameters**

| Parameter | Data Type | Required  | Explanation                                                                         |
| --------- | --------- | --------- | ----------------------------------------------------------------------------------- |
| name      | string    | mandatory | The name of the collection.                                                         |
| status    | string    | optional  | Visibility status of the collection (`public` or `private`). Defaults to `private`. |

**Example Request**

```json
{
    "name": "Test Collection",
    "status": "public" 
}
```

**Example Response (201 Created)**

```json
{
    "count": 2,
    "previous": null,
    "next": null,
    "results": [
        {
            "pk": 3,
            "status": "public",
            "name": "Test Collection",
            "slug": "test-collection-22958e2e492d428caXXXbbc346793860",
            "items": [
                {
                    "pk": 3,
                    "note": "Product note 1",
                    "product": {
                        "pk": 10,
                        "sku": "190XX919",
                        "attributes_kwargs": {},
                        "data_source": null,
                        "product_type": "0",
                        "name": "Test Product",
                        "parent": 2,
                        "is_seller_product": false,
                        "listing_code": null,
                        "absolute_url": "/product/10/",
                        "is_form_required": false,
                        "is_active": true,
                        "extra_attributes": {},
                        "is_listable": false,
                        "custom_attribute_set": null,
                        "attribute_set": null,
                        "group_products": [],
                        "attributes": {},
                        "base_code": null,
                        "productimage_set": []
                    },
                    "created_date": "2024-10-21T06:57:28.647606Z"
                },
            ],
            "public_url": "/wishlists/user-collection/test-collection-22958e2e492d428caXXXbbc346793860/"
        }
    ]
}
```

***

### `GET` List Collections

Retrieve a list of collections created by the user. Collections can be filtered by name or product ID.

**Path:** `https://{commerce_url}/wishlists/user-collections/`

**Request Parameters**

| Parameter   | Data Type | Explanation                                            |
| ----------- | --------- | ------------------------------------------------------ |
| search      | string    | Filter collections by name.                            |
| product\_id | integer   | Filter collections that contain a specific product ID. |

**Example Response (200 OK)**

```json
{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "pk": 1,
            "status": "private",
            "name": "Test Collection",
            "slug": "test-collection",
            "items": [],
            "public_url": null
        }
    ]
}
```

***

### `PATCH` Update a Collection

This endpoint allows users to rename or change the visibility status of a collection.

**Path:** `https://{commerce_url}/wishlists/user-collections/`

**Body Parameters**

| Parameter | Type   | Required | Description                                |
| --------- | ------ | -------- | ------------------------------------------ |
| name      | string | No       | The new name for the collection.           |
| status    | string | No       | New visibility status (public or private). |

**Example Request**

```json
{
    "name": "Public Collection",
    "status": "public"
}
```

**Example Response (200 OK)**

```json
{
    "pk": 1,
    "status": "public",
    "name": "Public Collection",
    "slug": "test-collection-2",
    "items": [],
    "public_url": "/wishlists/user-collection/test-collection-2/"
}
```

***

### `GET` Retrieve a Collection

Retrieve the details of a specific user collection by its primary key (pk).

**Path:** `https://{commerce_url}/wishlists/user-collections/<pk>/`

**Example Response (200 OK)**

```json
{
    "pk": 1,
    "status": "public",
    "name": "Public Collection",
    "slug": "test-collection-2",
    "items": [],
    "public_url": "/wishlists/user-collection/test-collection-2/"
}
```

***

### `DELETE` Delete a Collection

This endpoint allows users to delete a specific user collection by its primary key (pk).

**Path:** `https://{commerce_url}/wishlists/user-collections/<pk>/`

**Example Response (204 No Content)**

204 No Content successful response status code indicates that a user collection has been deleted.

***

### `POST` Add a Product to a Collection

Allows users to add a product to a specific collection, along with an optional note.

**Path:** `https://{commerce_url}/wishlists/user-collection-items/`

**Body Parameters**

| Parameter          | Type    | Required | Description                                                     |
| ------------------ | ------- | -------- | --------------------------------------------------------------- |
| product\_id        | integer | Yes      | The ID of the product to add.                                   |
| usercollection\_id | integer | Yes      | The ID of the collection.                                       |
| note               | string  | No       | An optional note associated with the product in the collection. |

**Example Request**

```json
{
    "product_id": 3239,
    "usercollection_id": 1,
    "note": "Test Note"
}
```

**Example Response (201 Created)**

```json
{
    "pk": 1,
    "product": {
        "pk": 3239,
        "name": "2-Li Aile Çerçevesi 13x18cm",
        "base_code": "1KCERX07XX",
        "sku": "26728XX0785XX",
        "product_type": "0",
        "is_active": true,
        "parent": null,
        "attributes": {
            "boyut": "13x18 CM",
            "uretim_yeri": "ÇİN",
            "renk": "STD",
            "integration_ProductCode": "1KCERV0784139",
            "integration_ProductHierarchyLevel01": "TEKSTİL DIŞI",
            "integration_ProductHierarchyLevel02": "Dekoratif",
            "integration_ProductAtt13Desc": "Dekoratif - %50+%50",
            "integration_ProductAtt12Desc": "%50 + %20 PROMOSYON",
        },
        "attributes_kwargs": {
            "integration_ProductHierarchyLevel01": {
                "value": "TEKSTİL DIŞI",
                "label": "TEKSTİL DIŞI"
            },
            "integration_ProductHierarchyLevel02": {
                "value": "Dekoratif",
                "label": "Dekoratif"
            }
            "renk": {
                "value": "STD",
                "label": "STD"
            },
        },
        "extra_attributes": {},
        "group_products": [],
        "productimage_set": [
            {
                "pk": 978,
                "status": "active",
                "image": "https://cdn-xxxx.akinon.net/products/2017/01/23/2022/ce59ad7a-15f8-44d6-9c0d-XXf0fe5405ba.jpg",
                "order": 0,
                "created_date": "2017-01-24T10:38:10.663088Z",
                "specialimage_set": []
            },
        ],
        "attribute_set": 62,
        "custom_attribute_set": null,
        "is_listable": true,
        "listing_code": null,
        "data_source": null
    },
    "created_date": "2021-09-21T08:15:50.875425Z",
    "note": "Test Note"
}
```

***

### `DELETE` Remove a Product from a Collection

This endpoint allows users to remove a product from a specific collection using the collection item’s primary key (pk).

**Path:** `https://{commerce_url}/wishlists/user-collection-items/<pk>/`

**Example Response (204 No Content)**

204 No Content successful response status code indicates that a product has been removed from a collection.

***

### `GET` Retrieve a Public User Collection

Allows anyone to retrieve the details of a public user collection using the collection's slug.

**Path:** `https://{commerce_url}/wishlists/user-collection/<slug>/`

**Example Response (200 OK)**

```json
{
    "status": "public",
    "name": "Test Coll",
    "items": [
        {
            "note": "test note",
            "pk": 6,
            "product": {
                "sku": "19051919",
                "attributes_kwargs": {},
                "data_source": null,
                "product_type": "1",
                "name": "test-prodc",
                "parent": null,
                "is_seller_product": false,
                "listing_code": null,
                "absolute_url": "/product/30/",
                "is_form_required": false,
                "is_active": true,
                "extra_attributes": {},
                "is_listable": false,
                "custom_attribute_set": null,
                "attribute_set": null,
                "group_products": [],
                "attributes": {},
                "base_code": null,
                "pk": 30,
                "productimage_set": []
            },
            "created_date": "2024-10-11T14:49:42.254439Z"
        }
    ],
    "public_url": "/wishlists/user-collection/test-coll/",
    "pk": 4,
    "slug": "test-coll"
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://apidocs.akinon.com/commerce/user-collections.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
