Entity Creation API
Overviewβ
The Entity Creation API allows authenticated users to create new entities in the Ring Platform. This endpoint supports creating various types of entities including companies, organizations, and projects with comprehensive metadata and visibility controls.
Endpoint Detailsβ
- URL:
/api/entities/create
- Method:
POST
- Authentication: Required (JWT Token)
- Rate Limit: 60 requests per minute for authenticated users
- Content-Type:
application/json
Authentication Requirementsβ
This endpoint requires authentication with one of the following roles:
- ADMIN - Full access to create any entity type
- CONFIDENTIAL - Can create confidential entities
- MEMBER - Can create public and member-visible entities
Request Formatβ
Headersβ
POST /api/entities/create
Content-Type: application/json
Authorization: Bearer <jwt_token>
Request Body Schemaβ
interface CreateEntityRequest {
name: string; // Entity name (required)
description?: string; // Entity description
website?: string; // Official website URL
email?: string; // Contact email
phone?: string; // Contact phone number
address?: string; // Physical address
category: string; // Entity category
tags?: string[]; // Searchable tags
visibility: 'public' | 'member' | 'confidential'; // Visibility level
logo?: string; // Logo URL
socialLinks?: { // Social media links
linkedin?: string;
twitter?: string;
facebook?: string;
github?: string;
};
foundedYear?: number; // Year founded
employeeCount?: string; // Employee count range
industry?: string; // Industry classification
location?: { // Geographic location
city?: string;
country?: string;
coordinates?: {
lat: number;
lng: number;
};
};
}
Example Request Bodyβ
{
"name": "TechCorp Solutions",
"description": "Leading software development company specializing in AI and blockchain solutions",
"website": "https://techcorp.example.com",
"email": "contact@techcorp.example.com",
"phone": "+380123456789",
"address": "123 Innovation Street, Kyiv, Ukraine",
"category": "Software Development",
"tags": ["AI", "Blockchain", "Web Development", "Mobile Apps"],
"visibility": "public",
"logo": "https://storage.example.com/logos/techcorp.png",
"socialLinks": {
"linkedin": "https://linkedin.com/company/techcorp",
"twitter": "https://twitter.com/techcorp",
"github": "https://github.com/techcorp"
},
"foundedYear": 2020,
"employeeCount": "11-50",
"industry": "Information Technology",
"location": {
"city": "Kyiv",
"country": "Ukraine",
"coordinates": {
"lat": 50.4501,
"lng": 30.5234
}
}
}
Response Formatβ
Success Response (201 Created)β
{
"id": "entity_123456789",
"name": "TechCorp Solutions",
"description": "Leading software development company specializing in AI and blockchain solutions",
"website": "https://techcorp.example.com",
"email": "contact@techcorp.example.com",
"phone": "+380123456789",
"address": "123 Innovation Street, Kyiv, Ukraine",
"category": "Software Development",
"tags": ["AI", "Blockchain", "Web Development", "Mobile Apps"],
"visibility": "public",
"logo": "https://storage.example.com/logos/techcorp.png",
"socialLinks": {
"linkedin": "https://linkedin.com/company/techcorp",
"twitter": "https://twitter.com/techcorp",
"github": "https://github.com/techcorp"
},
"foundedYear": 2020,
"employeeCount": "11-50",
"industry": "Information Technology",
"location": {
"city": "Kyiv",
"country": "Ukraine",
"coordinates": {
"lat": 50.4501,
"lng": 30.5234
}
},
"onlineStatus": "offline",
"lastOnline": null,
"createdAt": "2025-01-14T17:10:00Z",
"updatedAt": "2025-01-14T17:10:00Z",
"createdBy": "user_987654321"
}
Error Responsesβ
400 Bad Requestβ
{
"error": "Invalid JSON format"
}
401 Unauthorizedβ
{
"error": "Unauthorized"
}
403 Forbiddenβ
{
"error": "Only ADMIN or CONFIDENTIAL users can create confidential entities"
}
500 Internal Server Errorβ
{
"error": "Failed to create entity: Internal Server Error"
}
Code Examplesβ
JavaScript/TypeScriptβ
async function createEntity(entityData: CreateEntityRequest): Promise<Entity> {
const response = await fetch('/api/entities/create', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify(entityData)
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.error || 'Failed to create entity');
}
return response.json();
}
// Usage example
const newEntity = await createEntity({
name: "TechCorp Solutions",
description: "Leading software development company",
category: "Software Development",
visibility: "public",
website: "https://techcorp.example.com"
});
React Hook Exampleβ
import { useState } from 'react';
function useCreateEntity() {
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const createEntity = async (entityData: CreateEntityRequest) => {
setLoading(true);
setError(null);
try {
const response = await fetch('/api/entities/create', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(entityData),
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error);
}
const newEntity = await response.json();
return newEntity;
} catch (err) {
setError(err instanceof Error ? err.message : 'Unknown error');
throw err;
} finally {
setLoading(false);
}
};
return { createEntity, loading, error };
}
cURL Exampleβ
curl -X POST https://ring.ck.ua/api/entities/create \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{
"name": "TechCorp Solutions",
"description": "Leading software development company",
"category": "Software Development",
"visibility": "public",
"website": "https://techcorp.example.com",
"email": "contact@techcorp.example.com",
"tags": ["AI", "Blockchain", "Web Development"]
}'
Validation Rulesβ
Required Fieldsβ
name
: Must be 1-100 characterscategory
: Must be a valid categoryvisibility
: Must be 'public', 'member', or 'confidential'
Optional Field Constraintsβ
description
: Maximum 1000 characterswebsite
: Must be a valid URL formatemail
: Must be a valid email formatphone
: Must be a valid phone number formattags
: Maximum 10 tags, each 1-50 charactersfoundedYear
: Must be between 1800 and current yearemployeeCount
: Must be one of predefined ranges
Security Considerationsβ
- Role-Based Access: Users can only create entities with visibility levels appropriate to their role
- Input Validation: All input is validated and sanitized
- Rate Limiting: Prevents abuse with 60 requests per minute limit
- Audit Logging: All entity creation events are logged for security monitoring
Business Logicβ
- Automatic Fields:
id
,onlineStatus
,lastOnline
,createdAt
,updatedAt
, andcreatedBy
are automatically generated - Visibility Control: Confidential entities require ADMIN or CONFIDENTIAL role
- Duplicate Prevention: System checks for duplicate entities based on name and email
- Search Indexing: Created entities are automatically indexed for search functionality
Testing Examplesβ
Unit Test Exampleβ
describe('POST /api/entities/create', () => {
it('should create entity successfully with valid data', async () => {
const entityData = {
name: 'Test Entity',
category: 'Technology',
visibility: 'public'
};
const response = await request(app)
.post('/api/entities/create')
.set('Authorization', `Bearer ${validToken}`)
.send(entityData)
.expect(201);
expect(response.body).toHaveProperty('id');
expect(response.body.name).toBe('Test Entity');
});
it('should return 401 for unauthenticated requests', async () => {
const response = await request(app)
.post('/api/entities/create')
.send({ name: 'Test' })
.expect(401);
expect(response.body.error).toBe('Unauthorized');
});
});
Related Endpointsβ
- Get Entity by ID - Retrieve entity details
- Update Entity - Modify existing entity
- Delete Entity - Remove entity
- List Entities - Browse all entities
- Upload Entity Files - Attach files to entity
Changelogβ
- v1.0.0 - Initial implementation with basic entity creation
- v1.1.0 - Added social links and location support
- v1.2.0 - Enhanced validation and error handling
- v1.3.0 - Added confidential entity support