ZRPL
  • Welcome!
  • Quick Start
  • Reference
    • API Reference
      • Categories List
      • Category Details by ID
      • Create Simple Product
      • Config Product Creation
      • Product List
      • Update Existing Product
      • Product Details by SKU
      • Product Details by ID
      • Products in Category
      • Create Order
      • Order Details
      • Order History
      • Create Customer
      • Customer Token
      • Create Customer Cart
      • Add Item to Cart
      • View Cart
      • Update Cart
      • Delete Cart
      • Country Code
      • Set Shipping and Billing
      • Place Order
      • Customer Details
Powered by GitBook
On this page
  1. Reference
  2. API Reference

Create Simple Product

This API is offering to create Simple Product.

POST {{Base_url}}/rest/V1/products

The Magento API endpoint /rest/V1/products is designed to create a new product in the Magento store programmatically. It allows users to define a product's key attributes such as SKU, name, price, type, and visibility. Additionally, it supports adding media assets like images, which are uploaded in Base64-encoded format along with their MIME type (e.g., image/jpeg, image/png). The API also manages stock levels through extension attributes, enabling inventory control by specifying quantity and stock status.

Required Fields:

  • sku: Stock Keeping Unit - unique identifier for the product.

  • name: Name of the product.

  • attribute_set_id: ID of the attribute set (default: 4 for the default attribute set).

  • price: Price of the product.

  • status: Status of the product (1 for enabled, 0 for disabled).

  • visibility: Visibility of the product (1: Not Visible, 2: Catalog, 3: Search, 4: Catalog & Search).

  • type_id: Product type (e.g., simple, virtual, downloadable, etc.).

  • weight: Weight of the product (mandatory for simple products).

  • qty: inventory of the product (mandatory for simple products).

Headers

Name
Value

Content-Type

application/json

Authorization

Bearer <token>

Body

{
  "product": {
    "sku": "your-product-sku",
    "name": "Your Product Name",
    "attribute_set_id": 4,
    "price": 99.99,
    "status": 1,
    "visibility": 4,
    "type_id": "simple",
    "weight": 1.0,
"media_gallery_entries": [
            {
                "media_type": "image",
                "label": "Image Label",
                "position": 0,
                "disabled": 0,
                "types": [
                   "image",
                   "small_image",
                   "thumbnail",
                   "media_gallery"
                ],
                "file": "rbj1.jpeg",
                "content": {
                    "base64_encoded_data": "<base64_encoded_string>",
                    "type": "image/png",
                    "name": "rbj1.jpeg"
                 }
            }
        ],
    "extension_attributes": {
      "stock_item": {
        "qty": 10,
        "is_in_stock": true
      }
    },
    "custom_attributes": [
      {
        "attribute_code": "description",
       "value": "<p>html <b>description here</b></p>"     
 },
      {
        "attribute_code": "short_description",
        "value": "<p>html <b>short description here</b></p>"
      },
      {
        "attribute_code": "meta_title",
        "value": "Product Meta Title"
      },
      {
        "attribute_code": "meta_keyword",
        "value": "product, keywords, magento"
      },
      {
        "attribute_code": "meta_description",
        "value": "Meta description for the product."
      },
{
        "attribute_code": "Vendor_id",
        "value": "Vendor Product ID."
      }
    ]
  }
}
curl --location '{{Base_url}}/rest/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJraWQiOiIxIiwiYWxnIjoiSFMyNTYifQ.eyJ1aWQiOjU1LCJ1dHlwaWQiOjIsImlhdCI6MTczNjIyOTQwMiwiZXhwIjoxNzM2MjMzMDAyfQ.Ieac-0kIJbKSPCT8ncYF-X6DGPzHjdUT0vbYuNk4_uY' \
--header 'Cookie: PHPSESSID=6t4unirh1unu87ef0stp2sv3kv; private_content_version=5ab80b7def0c212f723edead3c971a19' \
--data '{
  "product": {
    "sku": "your-product-sku",
    "name": "Your Product Name",
    "attribute_set_id": 4,
    "price": 99.99,
    "status": 1,
    "visibility": 4,
    "type_id": "simple",
    "weight": 1.0,
"media_gallery_entries": [
            {
                "media_type": "image",
                "label": "Image Label",
                "position": 0,
                "disabled": 0,
                "types": [
                   "image",
                   "small_image",
                   "thumbnail",
                   "media_gallery"
                ],
                "file": "rbj1.jpeg",
                "content": {
                    "base64_encoded_data": "<base64_encoded_string>",
                    "type": "image/png",
                    "name": "rbj1.jpeg"
                 }
            }
        ],
    "extension_attributes": {
      "stock_item": {
        "qty": 10,
        "is_in_stock": true
      }
    },
    "custom_attributes": [
      {
        "attribute_code": "description",
       "value": "<p>html <b>description here</b></p>"     
 },
      {
        "attribute_code": "short_description",
        "value": "<p>html <b>short description here</b></p>"
      },
      {
        "attribute_code": "meta_title",
        "value": "Product Meta Title"
      },
      {
        "attribute_code": "meta_keyword",
        "value": "product, keywords, magento"
      },
      {
        "attribute_code": "meta_description",
        "value": "Meta description for the product."
      },
{
        "attribute_code": "Vendor_id",
        "value": "Vendor Product ID."
      }
    ]
  }
}
'

Product Attributes Overview

1. sku

  • Description: The unique identifier or stock-keeping unit for the product.

  • Example: "your-product-sku"

2. name

  • Description: The name of the product displayed to users.

  • Example: "Your Product Name"

3. attribute_set_id

  • Description: The ID of the attribute set that defines the attributes for this product.

  • Example: 4

4. price

  • Description: The price of the product.

  • Example: 99.99

5. status

  • Description: The availability status of the product.

    • 1 = Enabled

    • 2 = Disabled

  • Example: 1

6. visibility

  • Description: Determines the visibility of the product in the store.

    • 1 = Not visible individually

    • 2 = Catalog only

    • 3 = Search only

    • 4 = Catalog and Search

  • Example: 4

7. type_id

  • Description: The product type (e.g., simple, configurable, virtual, etc.).

  • Example: "simple"

8. weight

  • Description: The weight of the product, applicable for shipping calculations.

  • Example: 1.0


Media Attributes

9. media_gallery_entries

  • Description: Contains media files (images) associated with the product.

Subfields:

  1. media_type: Type of media (e.g., "image").

  2. label: Descriptive label for the media.

  3. position: The display order for the media.

  4. disabled: Specifies whether the media is disabled.

    • 0 = Enabled

    • 1 = Disabled

  5. types: Specifies where the media will be used (e.g., "image", "small_image", "thumbnail").

  6. file: The filename for the media.

  7. content: Contains the actual media content.

    • base64_encoded_data: Base64-encoded string of the image data.

    • type: MIME type of the image (e.g., "image/png", "image/jpeg" ).

    • name: Name of the media file.


Stock Attributes

10. extension_attributes.stock_item

  • Description: Contains stock-related information.

Subfields:

  1. qty: The quantity of the product available in stock.

  2. is_in_stock: Indicates stock status.

    • true = In stock

    • false = Out of stock


Custom Attributes

11. description

  • Description: A detailed description of the product in HTML format.

  • Example: "<p>html <b>description here</b></p>"

12. short_description

  • Description: A brief description of the product in HTML format.

  • Example: "<p>html <b>short description here</b></p>"

13. meta_title

  • Description: Meta title for the product, used for SEO purposes.

  • Example: "Product Meta Title"

14. meta_keyword

  • Description: Meta keywords for the product, used for SEO purposes.

  • Example: "product, keywords, magento"

15. meta_description

  • Description: Meta description for the product, used for SEO purposes.

  • Example: "Meta description for the product."

16. Vendor_id

  • Description: A custom attribute representing the Vendor product ID, if applicable.

  • Example: "Vendor Product ID."

Responses

{
    "id": 14535,
    "sku": "your-product-sku",
    "name": "Your Product Name",
    "attribute_set_id": 4,
    "price": 99.99,
    "status": 1,
    "visibility": 4,
    "type_id": "simple",
    "created_at": "2024-12-12 11:03:46",
    "updated_at": "2025-01-07 06:47:58",
    "weight": 1,
    "extension_attributes": {
        "website_ids": [
            1
        ],
        "stock_item": {
            "item_id": 432223,
            "product_id": 14535,
            "stock_id": 1,
            "qty": 10,
            "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": [
        {
            "id": 212270,
            "media_type": "image",
            "label": "Image Label",
            "position": 0,
            "disabled": false,
            "types": [],
            "file": "/r/b/rbj1_4_1.jpeg"
        },
        {
            "id": 212268,
            "media_type": "image",
            "label": "Image Label",
            "position": 0,
            "disabled": false,
            "types": [],
            "file": "/r/b/rbj1_3_2.jpeg"
        },
        {
            "id": 212269,
            "media_type": "image",
            "label": "Image Label",
            "position": 0,
            "disabled": false,
            "types": [
                "image",
                "small_image",
                "thumbnail"
            ],
            "file": "/r/b/rbj1_4.jpeg"
        },
        {
            "id": 212267,
            "media_type": "image",
            "label": "Image Label",
            "position": 0,
            "disabled": false,
            "types": [],
            "file": "/r/b/rbj1_3_1.jpeg"
        }
    ],
    "custom_attributes": [
        {
            "attribute_code": "short_description",
            "value": "<p>html <b>short description here</b></p>"
        },
        {
            "attribute_code": "image",
            "value": "/r/b/rbj1_4.jpeg"
        },
        {
            "attribute_code": "url_key",
            "value": "your-product-name"
        },
        {
            "attribute_code": "description",
            "value": "<p>html <b>description here</b></p>"
        },
        {
            "attribute_code": "meta_title",
            "value": "Product Meta Title"
        },
        {
            "attribute_code": "small_image",
            "value": "/r/b/rbj1_4.jpeg"
        },
        {
            "attribute_code": "options_container",
            "value": "container2"
        },
        {
            "attribute_code": "meta_keyword",
            "value": "product, keywords, magento"
        },
        {
            "attribute_code": "thumbnail",
            "value": "/r/b/rbj1_4.jpeg"
        },
        {
            "attribute_code": "meta_description",
            "value": "Meta description for the product."
        },
        {
            "attribute_code": "swatch_image",
            "value": "no_selection"
        },
        {
            "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": "Image Label"
        },
        {
            "attribute_code": "small_image_label",
            "value": "Image Label"
        },
        {
            "attribute_code": "thumbnail_label",
            "value": "Image Label"
        },
        {
            "attribute_code": "popular_product",
            "value": "0"
        },
        {
            "attribute_code": "tax_class_id",
            "value": "2"
        },
        {
            "attribute_code": "category_ids",
            "value": []
        },
        {
            "attribute_code": "sw_featured",
            "value": "0"
        }
    ]
}
{
    "message": "The \"sku\" attribute value is empty. Set the attribute and try again."
}
{
    "message": "The image MIME type is not valid or not supported."
}
{
    "message": "The consumer isn't authorized to access %resources."
}
PreviousCategory Details by IDNextConfig Product Creation

Last updated 4 months ago