Customer API
The Customer API allows you to create optical customers with their personal information, prescription data, and manage customer records. This endpoint supports file uploads for prescriptions and other documents.This endpoint uses
multipart/form-data format to support file uploads. Make
sure to include the proper headers when making requests.Endpoint Details
Base URL:https://joptic.jethings.com
Required Headers
Create Customer
Endpoint
Endpoint:POST /customerContent-Type:
multipart/form-data
Request Structure
The request usesmultipart/form-data format with:
jsonData: A JSON string containing the customer data- Files: Optional prescription documents or attachments uploaded with specific field names
Customer Data Structure
ThejsonData field must contain a JSON string with the following structure:
| Field | Type | Required | Description |
|---|---|---|---|
customerData | object | ✅ Yes | Personal information of the customer |
address | object | No | Customer address details |
opticData | object | No | Optical prescription measurements |
CustomerData Object
| Field | Type | Required | Description |
|---|---|---|---|
firstName | string | ✅ Yes | Customer’s first name |
lastName | string | ✅ Yes | Customer’s last name |
email | string | ✅ Yes | Customer’s email address (unique) |
phoneNumber | string | ✅ Yes | Customer’s phone number |
dateOfBirth | string (ISO Date) | ✅ Yes | Date of birth in ISO format |
sex | string | ✅ Yes | Gender: “male” or “female” |
Address Object
| Field | Type | Required | Description |
|---|---|---|---|
street | string | No | Street address |
city | string | No | City name |
zipCode | string | No | Postal/ZIP code |
state | string | No | State or province |
OpticData Object
Contains vision prescription data for different viewing distances:| Field | Type | Required | Description |
|---|---|---|---|
distanceVision | object | No | Distance vision prescription |
intermediateVision | object | No | Intermediate vision prescription |
nearVision | object | No | Near vision prescription |
rightEye and leftEye with:
sph(sphere): Spherical powercyl(cylinder): Cylindrical poweraxis: Axis measurement
Create Customer Examples
Example 1: Create Customer with Full Optical Data
Example 2: Create Customer with Minimal Data
Get Single Customer
Retrieve a specific customer by ID with all their details including personal information, address, and optical prescription data.Endpoint
Endpoint:GET /customer/:id
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | ✅ Yes | The ID of the customer |
Response (Success)
Response Schema
id(string): The customer IDisActive(boolean): Whether the customer is activecreatedAt(Date): Creation timestampupdatedAt(Date): Last update timestampdeletedAt(Date, nullable): Deletion timestamp (null if not deleted)localData(object): Customer personal informationaddress(object, optional): Customer address detailsopticData(object, optional): Optical prescription data
Error Responses
404 Not Found - Customer not found or doesn’t belong to storeExample Request
Get All Customers
Endpoint
Endpoint:GET /customer
Query Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
search | string | No | - | Search by first name, last name, or username |
name | string | No | - | Filter by specific name (first or last) |
isActive | boolean | No | - | Filter by active status |
page | number | No | 1 | Page number for pagination |
limit | number | No | 10 | Number of records per page |
sortBy | string | No | createdAt | Sort field: “name”, “status”, “createdAt”, “updatedAt” |
sortOrder | string | No | desc | Sort order: “asc” or “desc” |
Get Customers Examples
Example 1: Get All Customers (Default Pagination)
Example 2: Search Customers with Filters
Example 3: Get Active Customers Only
Update Customer
Update an existing customer’s information. You can update personal data, address, and optical prescription information. This endpoint also supports file uploads for updating prescription documents.Endpoint
Endpoint:PUT /customer/:idContent-Type:
multipart/form-data
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | ✅ Yes | The ID of the customer |
Request Structure
The request usesmultipart/form-data format with:
jsonData: A JSON string containing the customer data to update- Files: Optional prescription documents or attachments to update
Request Body Schema
All fields in thejsonData are optional. Only include the fields you want to update:
| Field | Type | Required | Description |
|---|---|---|---|
customerData | object | No | Personal information of the customer |
address | object | No | Customer address details |
opticData | object | No | Optical prescription measurements |
CustomerData Object (all fields optional)
| Field | Type | Description |
|---|---|---|
firstName | string | Customer’s first name |
lastName | string | Customer’s last name |
email | string | Customer’s email address (unique) |
phoneNumber | string | Customer’s phone number |
dateOfBirth | string (ISO Date) | Date of birth in ISO format |
sex | string | Gender: “male” or “female” |
Request Body Examples
Update only customer name:Response (Success)
Error Responses
404 Not Found - Customer not found or doesn’t belong to storeExample Requests
Notes
- Only customers belonging to the authenticated user’s store can be updated
- Email addresses must be unique per store
- All updates are performed within a database transaction
- Files can be updated by including new files with the same field names
- If a field is not included in the request, it will remain unchanged
Delete Customer
Delete a single customer. This performs a soft delete, setting thedeletedAt timestamp.
Endpoint
Endpoint:DELETE /customer/:id
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | ✅ Yes | The ID of the customer |
Response (Success)
Response Schema
message(string): Success messagecustomerId(string): The ID of the deleted customer
Error Responses
404 Not Found - Customer not found or doesn’t belong to storeExample Request
Notes
- Only customers belonging to the authenticated user’s store can be deleted
- This is a soft delete operation (sets
deletedAttimestamp) - Deleted customers are automatically excluded from GET requests
- Related data (address, opticData) may be handled based on cascade rules
Bulk Delete Customers
Delete multiple customers in a single request. Only customers belonging to the authenticated user’s store can be deleted.Endpoint
Endpoint:DELETE /customer/bulk
Request Body
Request Body Schema
ids(array of strings, required, min 1 item): Array of customer IDs to delete- Each ID must be a non-empty string
Response (Success)
Response Schema
message(string): Success message indicating how many customers were deleteddeletedCount(number): Number of customers successfully deleted
Error Responses
400 Bad Request - No customer IDs providedExample Request
Notes
- Only customers that belong to the authenticated user’s store will be deleted
- Already deleted customers (soft-deleted) are automatically excluded
- This is a soft delete operation (sets
deletedAttimestamp) - All operations are performed within a database transaction
Response Structures
Create Customer Response
Get Customers Response
Error Responses
400 Bad Request
403 Forbidden
409 Conflict
500 Internal Server Error
Important Notes
Store Access Requirements
Create Customer
Create Customer
- Requires user to be an owner of the store
- Validates
userStoreRelationfor active owner relationship - Missing ownership raises
ForbiddenException
Get Customers
Get Customers
- Requires user to have access to the store
- Can be owner or have assigned role/permissions
- Store access is validated via
userStoreRelation
Update Customer
Update Customer
- Requires user to be an owner of the store
- Only customers belonging to the store can be updated
- Email uniqueness is validated per store
Delete Customer
Delete Customer
- Requires user to be an owner of the store
- Only customers belonging to the store can be deleted
- Performs soft delete (sets deletedAt timestamp)
Email Handling
- Email addresses are trimmed and stored as provided
- Email must be unique per store
- Duplicate emails result in
ConflictException(409)
File Uploads
Supported Files
Upload prescription documents, ID cards, or related files
Grouped by fieldnameOptional Upload
Files are optional for customer creation
Basic customer data sufficientCustomer Status
- Customers are created with
isActive: trueby default - Status can be filtered in GET requests using
isActiveparameter - Deleted customers have
deletedAttimestamp (soft delete)
Name Display Logic
The customer name follows this fallback order:firstName + lastNamefrom local datauserNamefrom user table- Placeholder value if neither available
Pagination
- Default Behavior
- Custom Pagination
Summary
1
Authenticate
Obtain JWT token and ensure store access
2
Prepare Customer Data
Structure JSON with required customer information
3
Create Customer
POST request with multipart form data
4
Retrieve Customers
GET request with optional filters and pagination, or GET single customer by ID
5
Update Customer
PUT request with customer ID and updated data (multipart/form-data)
6
Delete Customer
DELETE request with customer ID, or bulk delete with array of IDs
7
Handle Response
Process customer data, pagination metadata, or deletion confirmation