Create Product Variant
Create a new product variant for a product in your easycart store.
Request
POST /products/{id}/variants
Path Parameters
Parameter | Type | Required | Description |
---|---|---|---|
id | string | Yes | Product UUID |
Request Body
Parameter | Type | Required | Description |
---|---|---|---|
type | string | Yes | Variant type ("one_time" or "recurring") |
name | string | No | Variant name (max 255 characters) |
recurring_options | object | No | Recurring options (required if type is "recurring") |
recurring_options.interval | string | No | Recurring interval ("day", "week", "month", "year") |
recurring_options.interval_count | integer | No | Number of intervals between charges |
amount | number | Yes | Price 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
Field | Type | Nullable | Description |
---|---|---|---|
id | string | No | Unique identifier for the product variant (UUID) |
type | string | No | Variant type ("one_time" or "recurring") |
recurring_options | object | Yes | Recurring options (null for one-time variants) |
recurring_options.interval | string | No | Recurring interval ("day", "week", "month", "year") |
recurring_options.interval_count | integer | No | Number of intervals between charges |
name | string | Yes | Variant name |
amount | integer | No | Price 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."
]
}
}