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

Success Response

Response Fields

Possible Errors

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

Example Requests

Basic Request (Default Pagination)

With Pagination

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

Success Response

Response Fields

Possible Errors

  • 401 Unauthorized: Missing or invalid authentication token
  • 404 Not Found: Product type not found
  • 500 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

Required Variant Object

Success Response

Response Fields

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


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

Request Body

Request Body Fields

Required Variant Object

Success Response

Response Fields

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


DTOs Overview

GetProductTypesDto (Query Parameters)

PaginatedProductTypesResponseDto

ProductTypeResponseDto

CreateProductTypeWithVariantsDto

AddRequiredVariantToProductTypeDto

CreateRequiredVariantDto

RequiredVariantResponse


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

Example Error Responses

400 Bad Request

404 Not Found

409 Conflict