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

x-store-id: <store_id>
Authorization: Bearer <token>
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

KeyValueRequiredDescription
x-store-idstringYesStore identifier (used by @StoreId() decorator)

Request Body

FieldTypeRequiredDescription
namestring✅ YesCustomer group name (max 255 characters)
defaultPriceListIdstring✅ YesID of the default price list for this group
descriptionstringNoOptional description of the customer group

Request Body Example

{
  "name": "VIP Customers",
  "defaultPriceListId": "price_list_123",
  "description": "Premium customers with special pricing"
}

Success Response

Status Code: 201 Created
{
  "id": "cgrp_abc123",
  "groupName": "VIP Customers",
  "description": "Premium customers with special pricing",
  "defaultPriceList": "price_list_123",
  "createdAt": "2025-11-03T10:00:00.000Z",
  "updatedAt": "2025-11-03T10:00:00.000Z"
}

Response Fields

FieldTypeDescription
idstringUnique customer group ID
groupNamestringCustomer group name
descriptionstringDescription of the group
defaultPriceListstringDefault price list ID
createdAtstringCreation timestamp (ISO 8601)
updatedAtstringLast update timestamp (ISO 8601)

Possible Errors

CodeMessage
400Bad Request - Invalid input data
401Unauthorized
403Forbidden - User does not have access to the store
500Internal Server Error

Example Requests

curl -X POST "https://joptic.jethings.com/customer-group" \
  -H "x-store-id: your-store-id" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "VIP Customers",
    "defaultPriceListId": "price_list_123",
    "description": "Premium customers with special pricing"
  }'
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

KeyValueRequiredDescription
x-store-idstringYesStore identifier (used by @StoreId() decorator)

Query Parameters

ParameterTypeRequiredDescriptionDefault
searchstringNoPartial match for group name or description
namestringNoPartial match for group name
isActivebooleanNoFilter by active status (currently not implemented)
pagenumberNoPage number (1-based)1
limitnumberNoItems per page (1–100)10
sortBystringNoSort field (name, createdAt, updatedAt)createdAt
sortOrderstringNoSort direction (asc or desc)desc

Success Response

Status Code: 200 OK
{
  "data": [
    {
      "id": "cgrp_abc123",
      "name": "VIP Customers",
      "description": "Premium customers with special pricing",
      "createdAt": "2025-10-01T09:00:00.000Z",
      "updatedAt": "2025-10-15T12:30:00.000Z"
    },
    {
      "id": "cgrp_def456",
      "name": "Regular Customers",
      "description": "Standard customer group",
      "createdAt": "2025-09-15T08:00:00.000Z",
      "updatedAt": "2025-09-20T10:00:00.000Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 10,
    "total": 4,
    "totalPages": 1,
    "hasNext": false,
    "hasPrev": false
  }
}

Response Fields

CustomerGroup Object

FieldTypeDescription
idstringUnique customer group ID
namestringGroup name
descriptionstringDescription of the group
createdAtstringCreation timestamp (ISO 8601)
updatedAtstringLast update timestamp (ISO 8601)

Pagination Object

FieldTypeDescription
pagenumberCurrent page number
limitnumberNumber of items per page
totalnumberTotal number of records
totalPagesnumberTotal pages available
hasNextbooleanWhether a next page exists
hasPrevbooleanWhether a previous page exists

Possible Errors

CodeMessage
401Unauthorized
403Forbidden - User does not have access to the store
500Internal Server Error

Example Requests

curl -X GET "https://joptic.jethings.com/customer-group?page=1&limit=10" \
  -H "x-store-id: your-store-id" \
  -H "Authorization: Bearer <token>"
Search by name or description:
curl -X GET "https://joptic.jethings.com/customer-group?search=VIP" \
  -H "x-store-id: your-store-id" \
  -H "Authorization: Bearer <token>"
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

ParameterTypeRequiredDescription
idstring✅ YesThe customer group ID

Success Response

Status Code: 200 OK
{
  "id": "cgrp_abc123",
  "name": "VIP Customers",
  "description": "Premium customers with special pricing",
  "createdAt": "2025-10-01T09:00:00.000Z",
  "updatedAt": "2025-10-15T12:30:00.000Z"
}

Response Fields

FieldTypeDescription
idstringUnique customer group ID
namestringGroup name
descriptionstringDescription of the group
createdAtstringCreation timestamp (ISO 8601)
updatedAtstringLast update timestamp (ISO 8601)

Possible Errors

CodeMessage
401Unauthorized
404Not Found - Customer group not found
500Internal Server Error

Example Requests

curl -X GET "https://joptic.jethings.com/customer-group/cgrp_abc123" \
  -H "Authorization: Bearer <token>"
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

FieldTypeRequiredDescription
idsarray<string>✅ YesArray of customer group IDs to delete

Request Body Example

{
  "ids": [
    "cgrp_abc123",
    "cgrp_def456",
    "cgrp_ghi789"
  ]
}

Success Response

Status Code: 200 OK
{
  "message": "Deleted 3 customer group(s)",
  "deletedCount": 3
}

Response Fields

FieldTypeDescription
messagestringSuccess message with count
deletedCountnumberNumber of customer groups deleted

Possible Errors

CodeMessage
400Bad Request - No IDs provided or empty array
401Unauthorized
404Not Found - No matching customer groups found
500Internal Server Error

Example Requests

curl -X DELETE "https://joptic.jethings.com/customer-group" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "ids": ["cgrp_abc123", "cgrp_def456"]
  }'
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

FieldTypeRequiredDescription
customerIdstring✅ YesID of the customer to assign
CustomerGroupIdstring✅ YesID of the customer group

Request Body Example

{
  "customerId": "customer_123",
  "CustomerGroupId": "cgrp_abc123"
}

Success Response

Status Code: 200 OK
{
  "id": "relation_xyz789",
  "customerGroupId": "cgrp_abc123",
  "customerId": "customer_123",
  "createdAt": "2025-11-03T10:00:00.000Z"
}

Response Fields

FieldTypeDescription
idstringUnique relation ID
customerGroupIdstringCustomer group ID
customerIdstringCustomer ID
createdAtstringCreation timestamp (ISO 8601)

Possible Errors

CodeMessage
400Bad Request - Invalid input data or missing required fields
401Unauthorized
404Not Found - Customer or customer group not found
500Internal Server Error

Example Requests

curl -X POST "https://joptic.jethings.com/customer-group/assign-group" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "customerId": "customer_123",
    "CustomerGroupId": "cgrp_abc123"
  }'
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

{
  "statusCode": 403,
  "message": "You do not have access to this store",
  "error": "Forbidden"
}

Common Error Scenarios

403 Forbidden - Store Access
{
  "statusCode": 403,
  "message": "You do not have access to this store"
}
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
{
  "statusCode": 400,
  "message": ["name must be a string", "defaultPriceListId must be a string"],
  "error": "Bad Request"
}
Occurs when required fields are missing or data types are incorrect. 404 Not Found - Customer or Group
{
  "statusCode": 404,
  "message": "Customer not found"
}
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

curl -X POST "https://joptic.jethings.com/customer-group" \
  -H "x-store-id: your-store-id" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Premium Members",
    "defaultPriceListId": "price_list_123",
    "description": "Customers with premium membership benefits"
  }'

Example 2: Get all customer groups with pagination

curl -X GET "https://joptic.jethings.com/customer-group?page=1&limit=20&sortBy=name&sortOrder=asc" \
  -H "x-store-id: your-store-id" \
  -H "Authorization: Bearer <token>"

Example 3: Search customer groups

curl -X GET "https://joptic.jethings.com/customer-group?search=VIP&page=1&limit=10" \
  -H "x-store-id: your-store-id" \
  -H "Authorization: Bearer <token>"

Example 4: Get customer group by ID

curl -X GET "https://joptic.jethings.com/customer-group/cgrp_abc123" \
  -H "Authorization: Bearer <token>"

Example 5: Delete multiple customer groups

curl -X DELETE "https://joptic.jethings.com/customer-group" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "ids": ["cgrp_abc123", "cgrp_def456"]
  }'

Example 6: Assign customer to group

curl -X POST "https://joptic.jethings.com/customer-group/assign-group" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "customerId": "customer_123",
    "CustomerGroupId": "cgrp_abc123"
  }'

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 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

EndpointMethodDescription
/customer-groupPOSTCreate a new customer group (rate: 10/min)
/customer-groupGETPaginated list of customer groups (rate: 60/min)
/customer-group/:idGETGet a customer group by ID (rate: 60/min)
/customer-groupDELETEDelete multiple customer groups (rate: 3/min)
/customer-group/assign-groupPOSTAssign a customer to a group (rate: 10/min)