Data Structure
List Employees
Retrieve a paginated list of employees.Query Parameters
The API supports the following query parameters using Spatie Query Builder:Filtering
- Simple Filters:
- Exact Filters:
- Partial Matching:
- Multiple Values:
Including Relationships
You can include related models in the response:site- The site this employee belongs touser- The user who created this employeecompany- The company this employee works fordocuments- All documents associated with this employee
Sorting
Sort results by one or multiple fields:first_namelast_nameemailcreated_atupdated_atcompany_id
Selecting Fields
Select specific fields to return:Pagination
Control the number of results per page:Create Employee
Create a new employee record.Validation Rules
| Field | Rules |
|---|---|
| company_id | Required, exists in companies table |
| first_name | Required, string, max:255 |
| last_name | Required, string, max:255 |
| Required, email, max:255 | |
| ssn | Required, format: XXX-XX-XXXX |
| address1 | Required, string, max:255 |
| city | Required, string, max:255 |
| state | Required for US addresses |
| zip | Required, string, max:20 |
| country | Required, ISO 2-letter code |
Update Employee
Update an existing employee’s information.Delete Employee
Delete an employee and their associated records.Relationships
BelongsTo Relationships
site- The site this employee belongs touser- The user who created this employeecompany- The company this employee works for
HasMany Relationships
documents- All documents associated with this employee
Security Considerations
- SSN Protection
- SSN is always masked in responses (XXX-XX-1234 format)
- Full SSN is only visible during creation
- SSN is encrypted at rest in the database
- SSN is transmitted securely via HTTPS
- Access Control
- Users can only access employees within their site
- Company-level permissions restrict access to employees
- Audit logs track all employee data access
Error Handling
HTTP Status Codes
- 401 Unauthenticated
- 403 Unauthorized
- 404 Not Found
- 422 Validation Error
Best Practices
- Data Validation
- Always validate SSN format (XXX-XX-XXXX)
- Verify email format and uniqueness
- Validate phone numbers for proper format
- Ensure address fields follow standards
- Security
- Use HTTPS for all API calls
- Implement rate limiting
- Monitor failed access attempts
- Regular security audits
- Performance
- Use sparse fieldsets for large datasets
- Include only needed relationships
- Implement proper indexing
- Cache frequently accessed data
- Compliance
- Follow data privacy regulations
- Implement data retention policies
- Maintain audit trails
- Regular compliance reviews

