Skip to main content

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

ParameterTypeRequiredDefaultDescription
pagenumberNo1Page number for pagination
limitnumberNo10Number of records per page (max: 100)
searchstringNo-Search across nameEn, nameFr, nameAr, code, and description
isActivebooleanNo-Filter by active status (true or false)
sortBystringNocreatedAtSort field: createdAt, updatedAt, nameEn, or code
sortOrderstringNodescSort order: asc or desc

Success Response

{
  "data": [
    {
      "id": "pt_123456",
      "code": "CLOTHING",
      "nameEn": "Clothing",
      "nameFr": "Vêtements",
      "nameAr": "ملابس",
      "description": "All types of clothing items",
      "icon": "https://example.com/icons/clothing.png",
      "isActive": true,
      "createdAt": "2024-01-15T10:00:00.000Z",
      "updatedAt": "2024-01-15T10:00:00.000Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 10,
    "total": 25,
    "totalPages": 3,
    "hasNext": true,
    "hasPrev": false
  }
}

Response Fields

FieldTypeDescription
dataarrayArray of product type objects
data[].idstringProduct type unique identifier
data[].codestringProduct type code
data[].nameEnstringProduct type name in English
data[].nameFrstringProduct type name in French
data[].nameArstringProduct type name in Arabic
data[].descriptionstring | undefinedProduct type description
data[].iconstring | undefinedIcon URL for the product type
data[].isActivebooleanWhether the product type is active
data[].createdAtstringCreation timestamp (ISO 8601)
data[].updatedAtstringLast update timestamp (ISO 8601)
paginationobjectPagination metadata
pagination.pagenumberCurrent page number
pagination.limitnumberNumber of items per page
pagination.totalnumberTotal number of product types
pagination.totalPagesnumberTotal number of pages
pagination.hasNextbooleanWhether there is a next page
pagination.hasPrevbooleanWhether there is a previous page

Possible Errors

  • 401 Unauthorized: Missing or invalid authentication token
  • 500 Internal Server Error: Server error

Example Requests

Basic Request (Default Pagination)

curl -X GET "https://jethings-backend.fly.dev/product-types" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

With Pagination

curl -X GET "https://jethings-backend.fly.dev/product-types?page=2&limit=20" \
  -H "Authorization: Bearer $ACCESS_TOKEN"
curl -X GET "https://jethings-backend.fly.dev/product-types?search=clothing" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

Filter by Active Status

curl -X GET "https://jethings-backend.fly.dev/product-types?isActive=true" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

With Sorting

curl -X GET "https://jethings-backend.fly.dev/product-types?sortBy=nameEn&sortOrder=asc" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

Combined Filters

curl -X GET "https://jethings-backend.fly.dev/product-types?page=1&limit=10&search=lens&isActive=true&sortBy=code&sortOrder=asc" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

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

ParameterTypeRequiredDescription
productTypeIdstringYesProduct type ID (UUID format)

Success Response

{
  "productTypeId": "pt_123456",
  "requiredVariants": [
    {
      "id": "rv_123456",
      "variantName": "Size",
      "allowedValues": ["S", "M", "L", "XL"]
    },
    {
      "id": "rv_789012",
      "variantName": "Color",
      "allowedValues": ["Red", "Blue", "Green"]
    }
  ]
}

Response Fields

FieldTypeDescription
productTypeIdstringThe product type ID
requiredVariantsarrayArray of required variant objects
requiredVariants[].idstringRequired variant unique identifier
requiredVariants[].variantNamestring | nullName of the variant (e.g., “Size”, “Color”)
requiredVariants[].allowedValuesstring[] | nullArray of allowed values for this variant

Possible Errors

  • 401 Unauthorized: Missing or invalid authentication token
  • 404 Not Found: Product type not found
  • 500 Internal Server Error: Server error

Example Request

curl -X GET "https://jethings-backend.fly.dev/product-types/pt_123456/required-variants" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

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

{
  "code": "CLOTHING",
  "nameEn": "Clothing",
  "nameFr": "Vêtements",
  "nameAr": "ملابس",
  "description": "All types of clothing items",
  "icon": "https://example.com/icons/clothing.png",
  "requiredVariants": [
    {
      "variantName": "Size",
      "allowedValues": ["S", "M", "L", "XL", "XXL"]
    },
    {
      "variantName": "Color",
      "allowedValues": ["Red", "Blue", "Green", "Black"]
    }
  ]
}

Request Body Fields

FieldTypeRequiredDescription
codestringYesProduct type code (unique identifier)
nameEnstringYesProduct type name in English
nameFrstringYesProduct type name in French
nameArstringYesProduct type name in Arabic
descriptionstringNoProduct type description
iconstringNoIcon URL for the product type
requiredVariantsarrayNoArray of required variants to create

Required Variant Object

FieldTypeRequiredDescription
variantNamestringYesName of the variant (e.g., “Size”, “Color”, “Material”)
allowedValuesstring[]NoArray of allowed values for this variant. If not provided, the variant accepts any value.

Success Response

{
  "productType": {
    "id": "pt_123456",
    "code": "CLOTHING",
    "nameEn": "Clothing",
    "nameFr": "Vêtements",
    "nameAr": "ملابس",
    "description": "All types of clothing items",
    "icon": "https://example.com/icons/clothing.png",
    "isActive": true,
    "createdAt": "2024-01-15T10:00:00.000Z",
    "updatedAt": "2024-01-15T10:00:00.000Z"
  },
  "requiredVariants": [
    {
      "id": "rv_123456",
      "variantName": "Size",
      "allowedValues": ["S", "M", "L", "XL", "XXL"]
    },
    {
      "id": "rv_789012",
      "variantName": "Color",
      "allowedValues": ["Red", "Blue", "Green", "Black"]
    }
  ]
}

Response Fields

FieldTypeDescription
productTypeobjectThe created product type object
requiredVariantsarrayArray of created required variant objects

Possible Errors

  • 400 Bad Request: Invalid request data or validation errors
  • 401 Unauthorized: Missing or invalid authentication token
  • 409 Conflict: Product type code already exists
  • 500 Internal Server Error: Server error

Example Request

curl -X POST "https://jethings-backend.fly.dev/product-types" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "code": "CLOTHING",
    "nameEn": "Clothing",
    "nameFr": "Vêtements",
    "nameAr": "ملابس",
    "description": "All types of clothing items",
    "icon": "https://example.com/icons/clothing.png",
    "requiredVariants": [
      {
        "variantName": "Size",
        "allowedValues": ["S", "M", "L", "XL", "XXL"]
      },
      {
        "variantName": "Color",
        "allowedValues": ["Red", "Blue", "Green", "Black"]
      }
    ]
  }'

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

ParameterTypeRequiredDescription
productTypeIdstringYesProduct type ID (UUID format)

Request Body

{
  "requiredVariants": [
    {
      "variantName": "Material",
      "allowedValues": ["Cotton", "Polyester", "Wool"]
    },
    {
      "variantName": "Pattern",
      "allowedValues": null
    }
  ]
}

Request Body Fields

FieldTypeRequiredDescription
requiredVariantsarrayYesArray of required variants to add

Required Variant Object

FieldTypeRequiredDescription
variantNamestringYesName of the variant (e.g., “Size”, “Color”, “Material”)
allowedValuesstring[]NoArray of allowed values for this variant. If null or not provided, the variant accepts any value.

Success Response

{
  "productTypeId": "pt_123456",
  "requiredVariants": [
    {
      "id": "rv_345678",
      "variantName": "Material",
      "allowedValues": ["Cotton", "Polyester", "Wool"]
    },
    {
      "id": "rv_901234",
      "variantName": "Pattern",
      "allowedValues": null
    }
  ]
}

Response Fields

FieldTypeDescription
productTypeIdstringThe product type ID
requiredVariantsarrayArray of created required variant objects
requiredVariants[].idstringRequired variant unique identifier
requiredVariants[].variantNamestring | nullName of the variant
requiredVariants[].allowedValuesstring[] | nullArray of allowed values (null if unrestricted)

Possible Errors

  • 400 Bad Request: Invalid request data or validation errors
  • 401 Unauthorized: Missing or invalid authentication token
  • 404 Not Found: Product type not found
  • 500 Internal Server Error: Server error

Example Request

curl -X POST "https://jethings-backend.fly.dev/product-types/pt_123456/required-variants" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "requiredVariants": [
      {
        "variantName": "Material",
        "allowedValues": ["Cotton", "Polyester", "Wool"]
      },
      {
        "variantName": "Pattern",
        "allowedValues": null
      }
    ]
  }'

DTOs Overview

GetProductTypesDto (Query Parameters)

{
  page?: number;           // Default: 1
  limit?: number;          // Default: 10, Max: 100
  search?: string;         // Search across nameEn, nameFr, nameAr, code, description
  isActive?: boolean;      // Filter by active status
  sortBy?: 'createdAt' | 'updatedAt' | 'nameEn' | 'code';  // Default: 'createdAt'
  sortOrder?: 'asc' | 'desc';  // Default: 'desc'
}

PaginatedProductTypesResponseDto

{
  data: ProductTypeResponseDto[];
  pagination: {
    page: number;
    limit: number;
    total: number;
    totalPages: number;
    hasNext: boolean;
    hasPrev: boolean;
  };
}

ProductTypeResponseDto

{
  id: string;
  code: string;
  nameEn: string;
  nameFr: string;
  nameAr: string;
  description?: string;
  icon?: string;
  isActive: boolean;
  createdAt: Date;
  updatedAt: Date;
}

CreateProductTypeWithVariantsDto

{
  code: string;
  nameEn: string;
  nameFr: string;
  nameAr: string;
  description?: string;
  icon?: string;
  requiredVariants?: CreateRequiredVariantDto[];
}

AddRequiredVariantToProductTypeDto

{
  requiredVariants: CreateRequiredVariantDto[];
}

CreateRequiredVariantDto

{
  variantName: string;
  allowedValues?: string[] | null;
}

RequiredVariantResponse

{
  id: string;
  variantName: string | null;
  allowedValues: string[] | null;
}

Business Logic

Product Type Creation Flow

  1. User creates a product type with multilingual names (English, French, Arabic)
  2. Product type is created with isActive: true by default
  3. Required variants can be created in the same transaction
  4. 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.
  • allowedValues can be:
    • An array of specific values (e.g., ["S", "M", "L"]) - restricts to these values only
    • null or omitted - allows any value to be entered
  • 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 errors
  • 401 Unauthorized: Missing or invalid authentication token
  • 404 Not Found: Product type not found
  • 409 Conflict: Product type code already exists
  • 500 Internal Server Error: Server error

Error Response Format

{
  "message": "Error description",
  "statusCode": 400
}

Example Error Responses

400 Bad Request

{
  "statusCode": 400,
  "message": "Validation failed",
  "error": "Bad Request"
}

404 Not Found

{
  "statusCode": 404,
  "message": "Product type not found",
  "error": "Not Found"
}

409 Conflict

{
  "statusCode": 409,
  "message": "Product type with code 'CLOTHING' already exists",
  "error": "Conflict"
}