# Config Product Creation

## Create Simple (Child) Product

<mark style="color:green;">`POST`</mark> `{{Base_url}}/rest/V1/products`

**Body**

{% tabs %}
{% tab title="Request Body" %}

```json
{
  "product": {
    "sku": "simple-product-sku1_color",
    "name": "Simple Product 1",
    "price": 50,
    "status": 1,
    "type_id": "simple",
    "attribute_set_id": 92,
    "visibility": 1,
    "extension_attributes": {
      "stock_item": {
        "qty": 100,
        "is_in_stock": true
      }
    },
    "custom_attributes": [
      {
        "attribute_code": "color_dropdown",
        "value": "1922" //Color Dropdown ID
      }
    ]
  }
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Curl" %}

```json
curl --location '{{Base_url}}/rest/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJraWQiOiIxIiwiYWxnIjoiSFMyNTYifQ.eyJ1aWQiOjU1LCJ1dHlwaWQiOjIsImlhdCI6MTczNjc1NDI3OSwiZXhwIjoxNzM2NzU3ODc5fQ.Fh_EDGygLD_8KVVV42qHv5DCVXsx5012T-jSd75Pfj4' \
--header 'Cookie: PHPSESSID=6t4unirh1unu87ef0stp2sv3kv; private_content_version=5ab80b7def0c212f723edead3c971a19' \
--data '{
  "product": {
    "sku": "simple-product-sku1_color",
    "name": "Simple Product 1",
    "price": 50,
    "status": 1,
    "type_id": "simple",
    "attribute_set_id": 92,
    "visibility": 1,
    "extension_attributes": {
      "stock_item": {
        "qty": 100,
        "is_in_stock": true
      }
    },
    "custom_attributes": [
      {
        "attribute_code": "color_dropdown",
        "value": "1922" 
      }
    ]
  }
}'
```

{% endtab %}
{% endtabs %}

#### **Product JSON Object Explanation**

**`"product"`**

* Root object representing the product data being created.

**Attributes in `product`:**

1. **`"sku"`**
   * **Type**: String.
   * Unique identifier for the product, e.g., `"simple-product-sku1_color"`.
2. **`"name"`**
   * **Type**: String.
   * The product's name, e.g., `"Simple Product 1"`.
3. **`"price"`**
   * **Type**: Float.
   * The product's price, e.g., `50`.
4. **`"status"`**
   * **Type**: Integer.
   * Product status: `1` for enabled, `0` for disabled.
5. **`"type_id"`**
   * **Type**: String.
   * Product type, e.g., `"simple"` for a simple product.
6. **`"attribute_set_id"`**
   * **Type**: Integer.
   * ID of the attribute set to which this product belongs (e.g., `92`).
7. **`"visibility"`**
   * **Type**: Integer.
   * Visibility on the storefront:
     * `1`: Not visible individually.
     * `2`: Catalog only.
     * `3`: Search only.
     * `4`: Catalog and search.

***

#### **Extension Attributes**

**`"stock_item"`**

* Represents stock and inventory data:
  * **`"qty"`**: Quantity in stock, e.g., `100`.
  * **`"is_in_stock"`**: Boolean to indicate if the product is in stock (`true` or `false`).

***

#### **Custom Attributes**

**`"custom_attributes"`**

* A list of additional attributes for the product:
  * **`"attribute_code"`**: Identifier for the attribute (e.g., `"color_dropdown"`).
  * **`"value"`**: Value for the attribute (e.g., `"1922"`, which might represent a color ID).

**Responses**

{% tabs %}
{% tab title="Success Response 200" %}

```javascript
{
    "id": 14602,
    "sku": "simple-product-sku1_color",
    "name": "Simple Product 1",
    "attribute_set_id": 92,
    "price": 50,
    "status": 1,
    "visibility": 1,
    "type_id": "simple",
    "created_at": "2025-01-10 11:49:09",
    "updated_at": "2025-01-13 07:51:39",
    "extension_attributes": {
        "website_ids": [
            1
        ],
        "stock_item": {
            "item_id": 432290,
            "product_id": 14602,
            "stock_id": 1,
            "qty": 100,
            "is_in_stock": true,
            "is_qty_decimal": false,
            "show_default_notification_message": false,
            "use_config_min_qty": true,
            "min_qty": 0,
            "use_config_min_sale_qty": 1,
            "min_sale_qty": 1,
            "use_config_max_sale_qty": true,
            "max_sale_qty": 100,
            "use_config_backorders": true,
            "backorders": 0,
            "use_config_notify_stock_qty": true,
            "notify_stock_qty": 1,
            "use_config_qty_increments": true,
            "qty_increments": 0,
            "use_config_enable_qty_inc": true,
            "enable_qty_increments": false,
            "use_config_manage_stock": true,
            "manage_stock": true,
            "low_stock_date": null,
            "is_decimal_divided": false,
            "stock_status_changed_auto": 0
        }
    },
    "options": [],
    "media_gallery_entries": [],
    "custom_attributes": [
        {
            "attribute_code": "url_key",
            "value": "simple-product-1"
        },
        {
            "attribute_code": "options_container",
            "value": "container2"
        },
        {
            "attribute_code": "purchase_price_cap",
            "value": "0.000000"
        },
        {
            "attribute_code": "msrp_display_actual_price_type",
            "value": "0"
        },
        {
            "attribute_code": "is_sclp",
            "value": "0"
        },
        {
            "attribute_code": "required_options",
            "value": "0"
        },
        {
            "attribute_code": "has_options",
            "value": "0"
        },
        {
            "attribute_code": "popular_product",
            "value": "0"
        },
        {
            "attribute_code": "tax_class_id",
            "value": "2"
        },
        {
            "attribute_code": "category_ids",
            "value": []
        },
        {
            "attribute_code": "sw_featured",
            "value": "0"
        },
        {
            "attribute_code": "color_dropdown",
            "value": "1922"
        }
    ]
}
```

{% endtab %}
{% endtabs %}

#### **Top-Level Attributes**

1. **`id`**
   * **Type**: Integer.
   * Unique identifier for the product in Magento (e.g., `14602`).
2. **`sku`**
   * **Type**: String.
   * Stock Keeping Unit (unique product identifier) used for inventory and management (e.g., `"simple-product-sku1_color"`).
3. **`name`**
   * **Type**: String.
   * The product name displayed to customers (e.g., `"Simple Product 1"`).
4. **`attribute_set_id`**
   * **Type**: Integer.
   * ID of the attribute set associated with this product (e.g., `92`). Attribute sets define the attributes available for the product.
5. **`price`**
   * **Type**: Float.
   * Base price of the product (e.g., `50`).
6. **`status`**
   * **Type**: Integer.
   * Indicates whether the product is enabled (`1`) or disabled (`0`) in the store.
7. **`visibility`**
   * **Type**: Integer.
   * Product visibility setting:
     * `1`: Not visible individually.
     * `2`: Catalog only.
     * `3`: Search only.
     * `4`: Catalog and search.
8. **`type_id`**
   * **Type**: String.
   * Specifies the product type. Here, `"simple"` indicates a simple product.
9. **`created_at`**
   * **Type**: String (timestamp).
   * Timestamp for when the product was created (`"2025-01-10 11:49:09"`).
10. **`updated_at`**
    * **Type**: String (timestamp).
    * Timestamp for when the product was last updated (`"2025-01-13 07:51:39"`).

***

#### **`extension_attributes`**

1. **`website_ids`**
   * **Type**: Array.
   * IDs of the websites where this product is available (e.g., `[1]`).
2. **`stock_item`**
   * Details about stock and inventory for this product:
     * **`item_id`**: Unique stock item ID (e.g., `432290`).
     * **`product_id`**: ID of the product associated with this stock item (e.g., `14602`).
     * **`stock_id`**: ID of the stock (e.g., `1`).
     * **`qty`**: Quantity in stock (e.g., `100`).
     * **`is_in_stock`**: Indicates if the product is in stock (`true`).
     * **`is_qty_decimal`**: Whether the product allows fractional quantities (`false`).
     * **`use_config_*`**: Boolean flags indicating if stock-related configurations are using global settings.
     * **`min_qty`**: Minimum stock quantity (e.g., `0`).
     * **`max_sale_qty`**: Maximum quantity that can be purchased in one order (e.g., `100`).
     * **`backorders`**: Backorder settings (`0` for no backorders).
     * **`notify_stock_qty`**: Threshold for low stock notification (e.g., `1`).
     * **`manage_stock`**: Indicates if stock management is enabled (`true`).

***

#### **`options`**

* **Type**: Array.
* Additional product options (empty here).

***

#### **`media_gallery_entries`**

* **Type**: Array.
* Media (images, videos) associated with the product (empty here).

***

#### **`custom_attributes`**

1. **`url_key`**
   * URL-friendly identifier for the product (e.g., `"simple-product-1"`).
2. **`options_container`**
   * Defines where product options are displayed on the product page (e.g., `"container2"`).
3. **`purchase_price_cap`**
   * Reserved for managing purchase price limits (e.g., `"0.000000"`).
4. **`msrp_display_actual_price_type`**
   * Determines how MSRP (Manufacturer Suggested Retail Price) is displayed (e.g., `"0"`).
5. **`is_sclp`**
   * Custom attribute, possibly related to product-specific logic (e.g., `"0"`).
6. **`required_options`**
   * Indicates if the product has required options (`"0"` means no required options).
7. **`has_options`**
   * Indicates if the product has any custom options (`"0"` means no options).
8. **`popular_product`**
   * Custom attribute to flag popular products (e.g., `"0"`).
9. **`tax_class_id`**
   * ID of the tax class applied to the product (e.g., `"2"`).
10. **`category_ids`**
    * List of category IDs to which the product belongs (empty here).
11. **`sw_featured`**
    * Custom attribute, possibly related to featured products (`"0"`).
12. **`color_dropdown`**
    * Custom attribute for color, storing a value that corresponds to an option ID (e.g., `"1922"`).

{% tabs %}
{% tab title="Bad Request 400 " %}

```json
{
    "message": "The \"sku\" attribute value is empty. Set the attribute and try again."
}
```

{% endtab %}

{% tab title="Token not Passed 401" %}

```json
{
    "message": "The consumer isn't authorized to access %resources."
}
```

{% endtab %}
{% endtabs %}

## Create Config (Parent) Product

<mark style="color:green;">`POST`</mark> `{{Base_url}}/rest/V1/products`

**Headers**

| Name          | Value              |
| ------------- | ------------------ |
| Content-Type  | `application/json` |
| Authorization | `Bearer <token>`   |

**Body**

{% tabs %}
{% tab title="Response Body" %}

```json
{
  "product": {
    "sku": "configurable-product-22",
    "name": "Configurable Product",
    "attribute_set_id": 92,
    "price": 20,
    "status": 1,
    "visibility": 4,
    "type_id": "configurable",
    "extension_attributes": {
      "stock_item": {
        "qty": 100,
        "is_in_stock": true
      },
      "configurable_product_options": [
        {
          "attribute_id": "681",  //Attribute ID available in  {{Base_url}}/rest/V1/products/attributes/color_dropdown
          "label": "color_dropdown",
          "position": 0,
          "values": [
            {
              "value_index": 1922  //Color Dropdown ID
            }
          ]
        }
      ],
      "configurable_product_links": [
        "14602" //Simple Product ID created above
      ]
    }
  }
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Curl" %}

```json
curl --location '{{Base_url}}/rest/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJraWQiOiIxIiwiYWxnIjoiSFMyNTYifQ.eyJ1aWQiOjU1LCJ1dHlwaWQiOjIsImlhdCI6MTczNjc1NDI3OSwiZXhwIjoxNzM2NzU3ODc5fQ.Fh_EDGygLD_8KVVV42qHv5DCVXsx5012T-jSd75Pfj4' \
--header 'Cookie: PHPSESSID=6t4unirh1unu87ef0stp2sv3kv; private_content_version=5ab80b7def0c212f723edead3c971a19' \
--data '{
  "product": {
    "sku": "configurable-product-22",
    "name": "Configurable Product",
    "attribute_set_id": 92,
    "price": 20,
    "status": 1,
    "visibility": 4,
    "type_id": "configurable",
    "extension_attributes": {
      "stock_item": {
        "qty": 100,
        "is_in_stock": true
      },
      "configurable_product_options": [
        {
          "attribute_id": "681",  
          "label": "color_dropdown",
          "position": 0,
          "values": [
            {
              "value_index": 1922  
            }
          ]
        }
      ],
      "configurable_product_links": [
        "14602" 
      ]
    }
  }
}'
```

{% endtab %}
{% endtabs %}

This cURL request is for creating a **configurable product** in Magento via the REST API. A configurable product allows customers to select options (like size or color) that are linked to simple products.

**Payload (Product Information):**

* **`sku`**
  * Unique identifier for the product (e.g., `"configurable-product-22"`).
* **`name`**
  * Name of the product (e.g., `"Configurable Product"`).
* **`attribute_set_id`**
  * Defines the attribute set for the product (e.g., `92`).
* **`price`**
  * Base price of the configurable product (e.g., `20`). This acts as a placeholder since pricing is tied to associated simple products.
* **`status`**
  * Product status: `1` for enabled, `0` for disabled.
* **`visibility`**
  * Visibility setting:
    * `4`: Visible in catalog and search.
* **`type_id`**
  * Indicates the product type. `"configurable"` specifies this is a configurable product.
* **`extension_attributes`:**
  1. **`stock_item`**
     * Details about inventory:
       * `qty`: Stock quantity (`100`).
       * `is_in_stock`: Indicates stock availability (`true`).
  2. **`configurable_product_options`**
     * Defines the configurable options for the product:
       * **`attribute_id`**: ID of the attribute used for configuration (e.g., `"681"` for color).
       * **`label`**: Label for the configurable attribute (e.g., `"color_dropdown"`).
       * **`position`**: Display order of the attribute (e.g., `0`).
       * **`values`**: Array of possible values for this attribute:
         * **`value_index`**: Option value (e.g., `1922`).
  3. **`configurable_product_links`**
     * Links the configurable product to its associated simple products:
       * **`14602`**: The `id` of a simple product that belongs to this configurable product.

**Responses**

{% tabs %}
{% tab title="Success Response 200" %}

```json
{
    "id": 14603,
    "sku": "configurable-product-22",
    "name": "Configurable Product",
    "attribute_set_id": 92,
    "price": 0,
    "status": 1,
    "visibility": 4,
    "type_id": "configurable",
    "created_at": "2025-01-10 11:53:21",
    "updated_at": "2025-01-13 07:57:15",
    "extension_attributes": {
        "website_ids": [
            1
        ],
        "stock_item": {
            "item_id": 432291,
            "product_id": 14603,
            "stock_id": 1,
            "qty": 0,
            "is_in_stock": true,
            "is_qty_decimal": false,
            "show_default_notification_message": false,
            "use_config_min_qty": true,
            "min_qty": 0,
            "use_config_min_sale_qty": 1,
            "min_sale_qty": 1,
            "use_config_max_sale_qty": true,
            "max_sale_qty": 100,
            "use_config_backorders": true,
            "backorders": 0,
            "use_config_notify_stock_qty": true,
            "notify_stock_qty": 1,
            "use_config_qty_increments": true,
            "qty_increments": 0,
            "use_config_enable_qty_inc": true,
            "enable_qty_increments": false,
            "use_config_manage_stock": true,
            "manage_stock": true,
            "low_stock_date": null,
            "is_decimal_divided": false,
            "stock_status_changed_auto": 0
        },
        "configurable_product_options": [
            {
                "id": 1128,
                "attribute_id": "681",
                "label": "color_dropdown",
                "position": 0,
                "values": [
                    {
                        "value_index": "1922",
                        "label": "New Color Option",
                        "sku": "simple-product-sku1_color",
                        "price": "50.00",
                        "special_price": "0.00",
                        "status": "1",
                        "is_in_stock": true,
                        "qty": 100
                    }
                ],
                "product_id": 14603
            }
        ],
        "configurable_product_links": [
            14602
        ]
    },
    "options": [],
    "media_gallery_entries": [
        {
            "id": 212576,
            "media_type": "external-video",
            "label": "Sample Video",
            "position": 2,
            "disabled": false,
            "types": [],
            "file": "/0/_/0_4.jpg",
            "extension_attributes": {
                "video_content": {
                    "media_type": "external-video",
                    "video_provider": "youtube",
                    "video_url": "https://www.youtube.com/watch?v=SEivYngJ4r0",
                    "video_title": "Lasko Purifier A504IN",
                    "video_description": "This is a sample video description.",
                    "video_metadata": ""
                }
            }
        }
    ],
    "custom_attributes": [
        {
            "attribute_code": "image",
            "value": "/0/_/0.jpg"
        },
        {
            "attribute_code": "url_key",
            "value": "configurable-product-aaaa"
        },
        {
            "attribute_code": "small_image",
            "value": "/0/_/0.jpg"
        },
        {
            "attribute_code": "options_container",
            "value": "container2"
        },
        {
            "attribute_code": "thumbnail",
            "value": "/0/_/0.jpg"
        },
        {
            "attribute_code": "purchase_price_cap",
            "value": "0.000000"
        },
        {
            "attribute_code": "msrp_display_actual_price_type",
            "value": "0"
        },
        {
            "attribute_code": "is_sclp",
            "value": "0"
        },
        {
            "attribute_code": "required_options",
            "value": "0"
        },
        {
            "attribute_code": "has_options",
            "value": "0"
        },
        {
            "attribute_code": "image_label",
            "value": "Sample Video"
        },
        {
            "attribute_code": "small_image_label",
            "value": "Sample Video"
        },
        {
            "attribute_code": "thumbnail_label",
            "value": "Sample Video"
        },
        {
            "attribute_code": "popular_product",
            "value": "0"
        },
        {
            "attribute_code": "tax_class_id",
            "value": "2"
        },
        {
            "attribute_code": "category_ids",
            "value": []
        },
        {
            "attribute_code": "sw_featured",
            "value": "0"
        }
    ]
}
```

{% endtab %}
{% endtabs %}

#### **Top-Level Attributes**

1. **`id`**
   * Unique identifier for the configurable product (e.g., `14603`).
2. **`sku`**
   * Stock Keeping Unit for the configurable product (e.g., `"configurable-product-22"`).
3. **`name`**
   * Product name (e.g., `"Configurable Product"`).
4. **`attribute_set_id`**
   * ID of the attribute set associated with this product (e.g., `92`).
5. **`price`**
   * Base price for the configurable product (e.g., `0`). Actual pricing comes from the associated simple products.
6. **`status`**
   * Product status: `1` for enabled, `0` for disabled.
7. **`visibility`**
   * Defines visibility:
     * `4`: Visible in catalog and search.
8. **`type_id`**
   * Product type: `"configurable"`.
9. **`created_at` / `updated_at`**
   * Timestamps for when the product was created and last updated.

***

#### **Extension Attributes**

1. **`website_ids`**
   * List of websites where this product is available (e.g., `[1]`).
2. **`stock_item`**
   * Inventory details for the product:
     * **`qty`**: Stock quantity (e.g., `0`).
     * **`is_in_stock`**: Indicates if the product is in stock (e.g., `true`).
     * Various other attributes control stock behavior (e.g., `min_qty`, `backorders`, etc.).
3. **`configurable_product_options`**
   * Defines the configurable options for this product:
     * **`id`**: Internal ID for this option (e.g., `1128`).
     * **`attribute_id`**: Attribute used for configuration (e.g., `"681"` for `color_dropdown`).
     * **`label`**: Display label for the option (e.g., `"color_dropdown"`).
     * **`values`**: Available options:
       * **`value_index`**: Option ID (e.g., `1922`).
       * **`label`**: Label for the option (e.g., `"New Color Option"`).
       * **`sku`**: SKU of the associated simple product (e.g., `"simple-product-sku1_color"`).
       * **`price`**: Price of the simple product (`50.00`).
       * **`status`**: Status of the simple product (`1`).
       * **`qty`**: Stock quantity for the simple product (`100`).
4. **`configurable_product_links`**
   * IDs of simple products associated with this configurable product (e.g., `[14602]`).

***

#### **Options**

* **`options`**
  * Array for custom product options (e.g., left empty here).

***

#### **Media Gallery Entries**

1. **`media_gallery_entries`**
   * Product media details:
     * **`id`**: Media ID (e.g., `212576`).
     * **`media_type`**: Type of media (e.g., `"external-video"`).
     * **`label`**: Media label (e.g., `"Sample Video"`).
     * **`file`**: File path or image/video reference (e.g., `"/0/_/0_4.jpg"`).
     * **`extension_attributes.video_content`**: Video details:
       * **`video_provider`**: Provider (e.g., `"youtube"`).
       * **`video_url`**: Video URL.
       * **`video_title`**: Title of the video.
       * **`video_description`**: Description of the video.

***

#### **Custom Attributes**

1. **`image`, `small_image`, `thumbnail`**
   * Paths to product images (e.g., `"/0/_/0.jpg"`).
2. **`url_key`**
   * SEO-friendly URL for the product (e.g., `"configurable-product-aaaa"`).
3. **`options_container`**
   * Placement of additional options on the product page (e.g., `"container2"`).
4. **`purchase_price_cap`**
   * Reserved for price limitations (e.g., `"0.000000"`).
5. **`msrp_display_actual_price_type`**
   * Defines how MSRP is displayed (e.g., `"0"`).
6. **`is_sclp`, `required_options`, `has_options`**
   * Flags indicating special behaviors or configurations (e.g., `"0"` means disabled).
7. **`image_label`, `small_image_label`, `thumbnail_label`**
   * Labels for different media types (e.g., `"Sample Video"`).
8. **`popular_product`**
   * Custom attribute indicating if this product is popular (e.g., `"0"`).
9. **`tax_class_id`**
   * Tax class applied to the product (e.g., `"2"`).
10. **`category_ids`**
    * Array of category IDs the product belongs to (e.g., `[]`).
11. **`sw_featured`**
    * Indicates if the product is featured (e.g., `"0"`).

{% tabs %}
{% tab title="Passed Invalid Simple Product ID 404 " %}

```javascript
{
    "message": "The product that was requested doesn't exist. Verify the product and try again."
}
```

{% endtab %}

{% tab title="Invalid Token 401 " %}

```python
{
    "message": "The consumer isn't authorized to access %resources."
}
```

{% endtab %}
{% endtabs %}


---

# 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://zrpl-co-1.gitbook.io/zrpl/reference/api-reference/config-product-creation.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.
