Skip to main content

Create Product Variant

Create a new product variant for a product in your easycart store.

Request

POST /products/{id}/variants

Path Parameters

ParameterTypeRequiredDescription
idstringYesProduct UUID

Request Body

ParameterTypeRequiredDescription
typestringYesVariant type ("one_time" or "recurring")
namestringNoVariant name (max 255 characters)
recurring_optionsobjectNoRecurring options (required if type is "recurring")
recurring_options.intervalstringNoRecurring interval ("day", "week", "month", "year")
recurring_options.interval_countintegerNoNumber of intervals between charges
amountnumberYesPrice in cents (minimum 0)

Example Request

curl -X POST "https://cart.easy.tools/api/v1/products/550e8400-e29b-41d4-a716-446655440000/variants" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"type": "one_time",
"name": "250g Package",
"amount": 1999
}'
curl -X POST "https://cart.easy.tools/api/v1/products/550e8400-e29b-41d4-a716-446655440000/variants" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"type": "recurring",
"name": "Monthly Subscription - 250g",
"recurring_options": {
"interval": "month",
"interval_count": 1
},
"amount": 1799
}'

Response

Success Response (201)

Returns the created product variant.

{
"id": "550e8400-e29b-41d4-a716-446655440002",
"type": "one_time",
"recurring_options": null,
"name": "250g Package",
"amount": 1999
}
{
"id": "550e8400-e29b-41d4-a716-446655440003",
"type": "recurring",
"recurring_options": {
"interval": "month",
"interval_count": 1
},
"name": "Monthly Subscription - 250g",
"amount": 1799
}

Response Fields

FieldTypeNullableDescription
idstringNoUnique identifier for the product variant (UUID)
typestringNoVariant type ("one_time" or "recurring")
recurring_optionsobjectYesRecurring options (null for one-time variants)
recurring_options.intervalstringNoRecurring interval ("day", "week", "month", "year")
recurring_options.interval_countintegerNoNumber of intervals between charges
namestringYesVariant name
amountintegerNoPrice in cents

Error Responses

Product Not Found (404)

{
"message": "Product with ID 550e8400-e29b-41d4-a716-446655440000 not found"
}

Validation Error (422)

{
"message": "The given data was invalid.",
"errors": {
"type": [
"The type field is required."
],
"recurring_options": [
"The recurring options field is required when type is recurring."
],
"amount": [
"The amount field is required."
]
}
}