Product Type API
Audience: Frontend engineers managing product types and their required variants.- Base URL:
https://jethings-backend.fly.dev - Content-Type:
application/json
Conventions
- All responses are JSON.
- Errors follow standard HTTP status codes with
{ message: string }body. - Unless noted, successful responses are
200 OK. - All endpoints require authentication via Bearer token.
Get All Product Types
GET/product-types
Requires Authentication: Bearer token in Authorization header
Retrieve all product types in the system with support for pagination, search, and filtering.
Query Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
page | number | No | 1 | Page number for pagination |
limit | number | No | 10 | Number of records per page (max: 100) |
search | string | No | - | Search across nameEn, nameFr, nameAr, code, and description |
isActive | boolean | No | - | Filter by active status (true or false) |
sortBy | string | No | createdAt | Sort field: createdAt, updatedAt, nameEn, or code |
sortOrder | string | No | desc | Sort order: asc or desc |
Success Response
Response Fields
| Field | Type | Description |
|---|---|---|
data | array | Array of product type objects |
data[].id | string | Product type unique identifier |
data[].code | string | Product type code |
data[].nameEn | string | Product type name in English |
data[].nameFr | string | Product type name in French |
data[].nameAr | string | Product type name in Arabic |
data[].description | string | undefined | Product type description |
data[].icon | string | undefined | Icon URL for the product type |
data[].isActive | boolean | Whether the product type is active |
data[].createdAt | string | Creation timestamp (ISO 8601) |
data[].updatedAt | string | Last update timestamp (ISO 8601) |
pagination | object | Pagination metadata |
pagination.page | number | Current page number |
pagination.limit | number | Number of items per page |
pagination.total | number | Total number of product types |
pagination.totalPages | number | Total number of pages |
pagination.hasNext | boolean | Whether there is a next page |
pagination.hasPrev | boolean | Whether there is a previous page |
Possible Errors
401 Unauthorized: Missing or invalid authentication token500 Internal Server Error: Server error
Example Requests
Basic Request (Default Pagination)
With Pagination
With Search
Filter by Active Status
With Sorting
Combined Filters
Get Product Type Required Variants
GET/product-types/:productTypeId/required-variants
Requires Authentication: Bearer token in Authorization header
Retrieve all required variants associated with a specific product type.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
productTypeId | string | Yes | Product type ID (UUID format) |
Success Response
Response Fields
| Field | Type | Description |
|---|---|---|
productTypeId | string | The product type ID |
requiredVariants | array | Array of required variant objects |
requiredVariants[].id | string | Required variant unique identifier |
requiredVariants[].variantName | string | null | Name of the variant (e.g., “Size”, “Color”) |
requiredVariants[].allowedValues | string[] | null | Array of allowed values for this variant |
Possible Errors
401 Unauthorized: Missing or invalid authentication token404 Not Found: Product type not found500 Internal Server Error: Server error
Example Request
Create Product Type with Variants
POST/product-types
Requires Authentication: Bearer token in Authorization header
Create a new product type along with its required variants in a single transaction.
Request Body
Request Body Fields
| Field | Type | Required | Description |
|---|---|---|---|
code | string | Yes | Product type code (unique identifier) |
nameEn | string | Yes | Product type name in English |
nameFr | string | Yes | Product type name in French |
nameAr | string | Yes | Product type name in Arabic |
description | string | No | Product type description |
icon | string | No | Icon URL for the product type |
requiredVariants | array | No | Array of required variants to create |
Required Variant Object
| Field | Type | Required | Description |
|---|---|---|---|
variantName | string | Yes | Name of the variant (e.g., “Size”, “Color”, “Material”) |
allowedValues | string[] | No | Array of allowed values for this variant. If not provided, the variant accepts any value. |
Success Response
Response Fields
| Field | Type | Description |
|---|---|---|
productType | object | The created product type object |
requiredVariants | array | Array of created required variant objects |
Possible Errors
400 Bad Request: Invalid request data or validation errors401 Unauthorized: Missing or invalid authentication token409 Conflict: Product type code already exists500 Internal Server Error: Server error
Example Request
Add Required Variants to Product Type
POST/product-types/:productTypeId/required-variants
Requires Authentication: Bearer token in Authorization header
Add one or more required variants to an existing product type.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
productTypeId | string | Yes | Product type ID (UUID format) |
Request Body
Request Body Fields
| Field | Type | Required | Description |
|---|---|---|---|
requiredVariants | array | Yes | Array of required variants to add |
Required Variant Object
| Field | Type | Required | Description |
|---|---|---|---|
variantName | string | Yes | Name of the variant (e.g., “Size”, “Color”, “Material”) |
allowedValues | string[] | No | Array of allowed values for this variant. If null or not provided, the variant accepts any value. |
Success Response
Response Fields
| Field | Type | Description |
|---|---|---|
productTypeId | string | The product type ID |
requiredVariants | array | Array of created required variant objects |
requiredVariants[].id | string | Required variant unique identifier |
requiredVariants[].variantName | string | null | Name of the variant |
requiredVariants[].allowedValues | string[] | null | Array of allowed values (null if unrestricted) |
Possible Errors
400 Bad Request: Invalid request data or validation errors401 Unauthorized: Missing or invalid authentication token404 Not Found: Product type not found500 Internal Server Error: Server error
Example Request
DTOs Overview
GetProductTypesDto (Query Parameters)
PaginatedProductTypesResponseDto
ProductTypeResponseDto
CreateProductTypeWithVariantsDto
AddRequiredVariantToProductTypeDto
CreateRequiredVariantDto
RequiredVariantResponse
Business Logic
Product Type Creation Flow
- User creates a product type with multilingual names (English, French, Arabic)
- Product type is created with
isActive: trueby default - Required variants can be created in the same transaction
- Each required variant can have optional allowed values to restrict input
Required Variants
- Required variants define what attributes must be specified when creating products of this type
- Examples: Size, Color, Material, Pattern, etc.
allowedValuescan be:- An array of specific values (e.g.,
["S", "M", "L"]) - restricts to these values only nullor omitted - allows any value to be entered
- An array of specific values (e.g.,
- Variants are linked to product types through a many-to-many relationship
Transaction Safety
- Creating a product type with variants uses a database transaction
- If any variant creation fails, the entire operation is rolled back
- Adding variants to an existing product type also uses transactions for consistency
Use Cases
- Clothing: Size, Color, Material
- Electronics: Model, Storage Capacity, Color
- Food Items: Weight, Unit, Expiry Date
- Custom Products: Any custom attributes defined by the business
Error Responses
Common Error Codes
400 Bad Request: Invalid request data or validation errors401 Unauthorized: Missing or invalid authentication token404 Not Found: Product type not found409 Conflict: Product type code already exists500 Internal Server Error: Server error