Create an Option

Endpoint Overview

Product options allow customers to customize products before purchase. This endpoint enables you to create new options for your products, such as size, color, or other configurable features.

POST /api/options/

Creates a new option for a specific product.

Request Parameters

Pass the following parameters in the HTTP request body according to your specified Content-Type:

Basic Option Information

Parameter Type Required Description
product_id* integer Yes The unique identifier of the product that the option is associated with.
option_name* string Yes The name of the option as it will appear to customers.
option_type string No The type of option interface. Defaults to S (Select box) if not specified.
required string No Determines if customers must specify this option before adding the product to cart. Use Y for Yes and N for No.
inventory string No Determines if the option is taken into account when forming the product inventory. Use Y for Yes and N for No.
main_pair object No An object with the icons of the option variants.

Option Types

Code Type Description
S Select box A dropdown list of options
R Radiogroup A group of radio buttons (select one)
C Checkbox A single checkbox option
I Text (one line) A text input field
T Text area A multi-line text input area
F File A file upload option

Option Variants

For select boxes, radiogroups, and checkboxes, you can define variants as part of the request:

Parameter Type Required Description
variants object No An object containing the option variants. Each variant can have its own properties like name, price modifier, etc.

Example Request

{
  "product_id": "12",
  "option_name": "Packaging",
  "option_type": "R",
  "required": "Y",
  "inventory": "N",
  "main_pair": {
    "icon": {
      "image_path": {
        "1": "https://www.venddor.com.br/image1.jpg",
        "2": "https://www.venddor.com.br/image2.jpg"
      }
    }
  },
  "variants": {
    "1": {
      "variant_name": "None"
    },
    "2": {
      "variant_name": "Gift wrap",
      "modifier_type": "A",
      "modifier": "5"
    }
  }
}

This request creates a new "Packaging" option for the product with product_id=12. The option has two variants:

  • None - Default packaging with no price change
  • Gift wrap - Adds $5 to the product price (modifier_type="A" for absolute value)
Note: For the modifier_type field, use A for absolute value (like $5) and P for percentage (like 10%).

Response Format

Success Response (201 Created)

{
  "option_id": 27
}

Error Response (400 Bad Request)

Returned when the option couldn't be created due to invalid parameters or other issues.

Implementation Notes

Product options enhance your store by giving customers the ability to customize products. When creating options, consider the following best practices:

Tip: For visual options like colors or patterns, include images for each variant to improve the shopping experience.