Skip to main content

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 /customer
Content-Type: multipart/form-data

Request Structure

The request uses multipart/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

The jsonData field must contain a JSON string with the following structure:

CustomerData Object

Address Object

OpticData Object

Contains vision prescription data for different viewing distances: Each vision object contains rightEye and leftEye with:
  • sph (sphere): Spherical power
  • cyl (cylinder): Cylindrical power
  • axis: Axis measurement

Create Customer Examples

Example 1: Create Customer with Full Optical Data

Success Response:

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

Response (Success)

Response Schema

  • id (string): The customer ID
  • isActive (boolean): Whether the customer is active
  • createdAt (Date): Creation timestamp
  • updatedAt (Date): Last update timestamp
  • deletedAt (Date, nullable): Deletion timestamp (null if not deleted)
  • localData (object): Customer personal information
  • address (object, optional): Customer address details
  • opticData (object, optional): Optical prescription data

Error Responses

404 Not Found - Customer not found or doesn’t belong to store

Example Request


Get All Customers

Endpoint

Endpoint: GET /customer

Query Parameters


Get Customers Examples

Example 1: Get All Customers (Default Pagination)


Example 2: Search Customers with Filters

Success Response:

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/:id
Content-Type: multipart/form-data

Path Parameters

Request Structure

The request uses multipart/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 the jsonData are optional. Only include the fields you want to update:

CustomerData Object (all fields optional)

Request Body Examples

Update only customer name:
Update multiple fields:

Response (Success)

Error Responses

404 Not Found - Customer not found or doesn’t belong to store
400 Bad Request - Validation errors
409 Conflict - Email already exists

Example 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 the deletedAt timestamp.

Endpoint

Endpoint: DELETE /customer/:id

Path Parameters

Response (Success)

Response Schema

  • message (string): Success message
  • customerId (string): The ID of the deleted customer

Error Responses

404 Not Found - Customer not found or doesn’t belong to store

Example Request

Notes

  • Only customers belonging to the authenticated user’s store can be deleted
  • This is a soft delete operation (sets deletedAt timestamp)
  • 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 deleted
  • deletedCount (number): Number of customers successfully deleted

Error Responses

400 Bad Request - No customer IDs provided
404 Not Found - No valid customers found to delete

Example 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 deletedAt timestamp)
  • 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

  • Requires user to be an owner of the store
  • Validates userStoreRelation for active owner relationship
  • Missing ownership raises ForbiddenException
  • Requires user to have access to the store
  • Can be owner or have assigned role/permissions
  • Store access is validated via userStoreRelation
  • Requires user to be an owner of the store
  • Only customers belonging to the store can be updated
  • Email uniqueness is validated per store
  • 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 fieldname

Optional Upload

Files are optional for customer creation
Basic customer data sufficient

Customer Status

  • Customers are created with isActive: true by default
  • Status can be filtered in GET requests using isActive parameter
  • Deleted customers have deletedAt timestamp (soft delete)

Name Display Logic

The customer name follows this fallback order:
  1. firstName + lastName from local data
  2. userName from user table
  3. Placeholder value if neither available

Pagination

Returns 10 most recent customers by default

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
This API provides comprehensive customer management for optical stores, including prescription data storage, file uploads, flexible querying with pagination and filtering, and full CRUD operations for customer records.

Purchase Invoice API

Create purchase invoices and manage inventory

Store Management

Manage stores and permissions