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://j-optic.fly.dev
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 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
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
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
5
Handle Response
Process customer data and pagination metadata