Skip to main content

Customer Group API

The Customer Group API enables optical stores to organize customers into groups, manage group memberships, and associate default price lists with customer groups.
All Customer Group API endpoints require authentication. Routes that operate in a store context also require a valid x-store-id header.

Overview

Customer groups can be:
  • Created with a name, description, and default price list
  • Listed with pagination, filtering, and sorting
  • Retrieved by ID for individual group details
  • Deleted in bulk operations
  • Used to assign customers to groups for pricing and organization
  • Associated with default price lists for automatic pricing

Endpoint Details

Base URL: https://joptic.jethings.com
Content-Type: application/json

Required Headers

Endpoints that require x-store-id enforce store-level access control. Ensure the requesting user has an active relation with the store.

Authentication

All endpoints require user authentication. The user ID is extracted from the JWT token (req.user.sub), and store access is validated via the @StoreId() decorator.

Rate Limiting

Endpoints are protected with rate limiting:
  • GET endpoints: 60 requests per minute (long throttle)
  • POST endpoints: 10 requests per minute (medium throttle)
  • DELETE endpoints: 3 requests per minute (short throttle)

Create Customer Group

POST /customer-group Create a new customer group with an optional description and default price list association. Requires Authentication: Bearer token in Authorization header
Requires Header: x-store-id
Rate Limited: 10 requests per minute

Required Headers

Request Body

Request Body Example

Success Response

Status Code: 201 Created

Response Fields

Possible Errors

Example Requests

The customer group is created without store association in the current implementation. The default price list ID should reference an existing price list in your system.

Get All Customer Groups

GET /customer-group Retrieve a paginated list of customer groups with optional filters and search capabilities. Requires Authentication: Bearer token in Authorization header
Requires Header: x-store-id
Rate Limited: 60 requests per minute

Required Headers

Query Parameters

Success Response

Status Code: 200 OK

Response Fields

CustomerGroup Object

Pagination Object

Possible Errors

Example Requests

Search by name or description:
The search parameter performs a case-insensitive search across both group name and description fields. Results are paginated for performance. Default sorting is by creation date (newest first).

Get Customer Group by ID

GET /customer-group/:id Retrieve a single customer group by its ID. Requires Authentication: Bearer token in Authorization header Rate Limited: 60 requests per minute

Path Parameters

Success Response

Status Code: 200 OK

Response Fields

Possible Errors

Example Requests

This endpoint does not require the x-store-id header. It retrieves the customer group by ID regardless of store association.

Delete Customer Groups (Bulk)

DELETE /customer-group Delete one or more customer groups by their IDs. This is a bulk delete operation that allows removing multiple groups in a single request. Requires Authentication: Bearer token in Authorization header Rate Limited: 3 requests per minute

Request Body

Request Body Example

Success Response

Status Code: 200 OK

Response Fields

Possible Errors

Example Requests

This is a bulk delete operation. Only valid customer group IDs are deleted (invalid IDs are ignored). Returns the count of successfully deleted groups. This operation is permanent and cannot be undone. Rate limited to 3 requests per minute for safety.

Assign Customer to Group

POST /customer-group/assign-group Assign a customer to a customer group. This creates a relationship between a customer and a customer group. Requires Authentication: Bearer token in Authorization header Rate Limited: 10 requests per minute

Request Body

Request Body Example

Success Response

Status Code: 200 OK

Response Fields

Possible Errors

Example Requests

If a customer is already assigned to the group, the operation may fail or create a duplicate relation depending on your database constraints. Ensure the customer and customer group IDs exist before assignment.

Business Logic

Customer Group Management

Default Price List AssociationCustomer groups can have default price lists:
  1. When creating a group, you must specify a defaultPriceListId
  2. This price list can be used for automatic pricing when processing orders for customers in the group
  3. The price list ID must reference an existing price list in your system
  4. Default price lists help streamline pricing for groups of customers
Store Access ControlCustomer group operations are protected:
  1. Users must have an active relation with the store (via userStoreRelation)
  2. The x-store-id header is required for store-scoped operations
  3. If a user doesn’t have access to the store, a 403 Forbidden error is returned
  4. This ensures users can only manage customer groups for stores they have access to
Search FunctionalityThe search parameter is flexible:
  1. Searches across both group name and description fields
  2. Uses case-insensitive partial matching (LIKE queries)
  3. The name parameter is an alias for searching by name specifically
  4. Search results are combined and paginated
Sorting OptionsCustomer groups can be sorted by:
  1. name - Sort alphabetically by group name
  2. createdAt - Sort by creation date (default)
  3. updatedAt - Sort by last update date
  4. Sort order can be asc (ascending) or desc (descending, default)
Customer AssignmentAssigning customers to groups:
  1. Creates a relation between a customer and a customer group
  2. A customer can be assigned to multiple groups (if your schema allows)
  3. The assignment creates a record in the customerGroupRelation table
  4. This relation can be used for filtering, pricing, and reporting

Customer Group States

Active Group

Active
Group is available for customer assignment

With Default Price List

Price List Associated
Group has a default price list for automatic pricing

Searchable

Searchable
Groups can be found by name or description

Sortable

Sortable
Groups can be sorted by name, createdAt, or updatedAt

Error Responses

All endpoints may return standard HTTP error codes:
  • 400 Bad Request - Invalid request parameters or body
  • 401 Unauthorized - Missing or invalid authentication token
  • 403 Forbidden - User does not have access to the store
  • 404 Not Found - Resource not found (customer, customer group, etc.)
  • 429 Too Many Requests - Rate limit exceeded
  • 500 Internal Server Error - Server error

Error Response Format

Common Error Scenarios

403 Forbidden - Store Access
Occurs when the user doesn’t have an active relation with the store specified in the x-store-id header. 400 Bad Request - Validation Error
Occurs when required fields are missing or data types are incorrect. 404 Not Found - Customer or Group
Occurs when trying to assign a customer that doesn’t exist or reference a non-existent customer group.

Usage Examples

Example 1: Create a customer group

Example 2: Get all customer groups with pagination

Example 3: Search customer groups

Example 4: Get customer group by ID

Example 5: Delete multiple customer groups

Example 6: Assign customer to group


Best Practices

  • Use descriptive group names that indicate the customer category or tier
  • Organize customers by membership level, purchase behavior, or business relationship
  • Use descriptions to provide additional context about the group’s purpose
  • Keep group names consistent and meaningful
  • Associate appropriate price lists with customer groups for automatic pricing
  • Ensure the price list ID exists before creating a group
  • Update price list associations when business needs change
  • Use price lists to differentiate pricing for different customer segments
  • Assign customers to groups during customer creation for better organization
  • Use groups to apply consistent pricing across customer segments
  • Monitor group membership for reporting and analytics
  • Reassign customers to groups when their status changes
  • Use pagination when fetching large lists of groups
  • Default limit of 10 is suitable for most use cases
  • Maximum limit of 100 should be used sparingly
  • Always check hasNext and hasPrev for navigation
  • Use the search parameter for quick lookups by name or description
  • Combine search with pagination for efficient data retrieval
  • Use the name parameter for more specific name-based filtering
  • Leverage sorting options to organize results by relevance
  • GET endpoints: 60 requests per minute
  • POST endpoints: 10 requests per minute
  • DELETE endpoints: 3 requests per minute
  • Implement retry logic with exponential backoff for rate limit errors
  • Batch operations when possible to reduce API calls
  • Always check for 403 errors when accessing store-scoped endpoints
  • Validate customer and group IDs before assignment
  • Handle 400 validation errors by checking request body structure
  • Implement proper error handling for network and server errors

Customer groups work in conjunction with other customer and pricing management endpoints:
  • Customer API (/customer) - Manage customers that can be assigned to groups
  • Price List API (/price-lists) - Manage price lists that can be associated with groups
Customer groups help organize customers by category, making it easier to manage pricing, apply discounts, and segment customers for marketing and reporting purposes. Groups can be associated with default price lists for automatic pricing.

Summary


Customer API

Create and manage optical customers

Price List API

Manage price lists for customer groups