Appearance
Create API Key ๐ โ
Creates a new API key. The key value is automatically generated by the system.
Endpoint โ
POST /api/ApiKey/create
๐ JWT Required
x-api-key: <your-api-key>
Authorization: Bearer <jwt-token>
Content-Type: application/json
Authentication Required
๐ JWT Required - Both API key and JWT token are required
Request Example โ
bash
curl -X POST https://shipyo.it/api/ApiKey/create \
-H "x-api-key: ak_1234567890abcdef" \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json" \
-d '{
"name": "Mobile App API Key",
"allowedIp": "192.168.1.200",
"isActive": true,
"description": "API key for mobile application integration"
}'
Request Body โ
json
{
"name": "Mobile App API Key",
"allowedIp": "192.168.1.200",
"isActive": true,
"description": "API key for mobile application integration"
}
Fields:
name
(string, required): Human-readable name for the API keyallowedIp
(string, optional): IP address restriction (null for no restriction)isActive
(boolean, required): Whether the API key should be active immediatelydescription
(string, optional): Description of the API key's purpose
Success Response โ
201 API Key Created Successfully
New API key has been generated with secure random value
Example Response:
{
"success": true,
"data": {
"id": 3,
"key": "ak_3456789012bcdef3456789012",
"name": "Mobile App API Key",
"isActive": true,
"description": "API key for mobile application integration",
"allowedIp": "192.168.1.200",
"createdDate": "2024-08-25T15:30:00Z",
"permissions": [
"read",
"write"
],
"tenantId": 1,
"expiresAt": null
},
"message": "API Key created successfully"
}
Response Fields โ
Field | Type | Description | Security Notes |
---|---|---|---|
success | boolean | Always true for successful creation | Operation status |
data.id | number | Unique API key identifier | Use for management operations |
data.key | string | ACTUAL API KEY VALUE | โ ๏ธ Store securely - shown only once |
data.name | string | Human-readable API key name | For identification purposes |
data.isActive | boolean | API key activation status | Must be true to use |
data.description | string | Purpose description | Documentation |
data.allowedIp | string/null | IP address restriction | Security constraint |
data.createdDate | string | ISO timestamp of creation | Audit information |
data.permissions | array | Granted permissions | Access scope |
data.tenantId | number | Associated tenant ID | Scope limitation |
data.expiresAt | string/null | Expiration date | null = no expiration |
message | string | Success confirmation | Human-readable message |
๐ Critical Security Information โ
API Key Value - First and Only Display โ
- ๐จ Store Immediately: The
key
value is only shown once upon creation - ๐ Secure Storage: Store in environment variables or secure configuration
- โ Cannot Retrieve: You cannot get the full key value again later
- ๐ Regeneration: If lost, you must create a new API key
IP Address Restrictions โ
- ๐ allowedIp: If set, API key only works from this IP address
- ๐ null value: No IP restriction (works from any IP - less secure)
- ๐ก๏ธ Security recommendation: Always set IP restrictions for production
Immediate Usage โ
bash
# Test the newly created API key immediately
curl -X GET https://shipyo.it/api/Token/generate-from-apikey \
-H "x-api-key: ak_3456789012bcdef3456789012"
Post-Creation Actions โ
Immediate steps required:
- ๐พ Save the key value in your application's secure configuration
- ๐งช Test the key with a simple API call to verify it works
- ๐ Document usage in your deployment notes
- ๐ Set up monitoring for key usage patterns
- ๐ Plan rotation schedule for security best practices
Important Notes โ
- Tenant Scope: API key is automatically associated with your current tenant
- Permissions: Inherit from your user role and tenant policies
- Activation: Key is immediately active and ready to use
- Management: Use the returned
id
for future update/delete operations - Audit: Key creation is logged for security monitoring
Next Steps โ
- Store the key securely in your application
- Update your application to use the new API key
- Test all integrations with the new key
- Monitor usage through API logs
- Schedule regular rotation for enhanced security
Error Responses โ
400 Bad Request
Request contains invalid data or validation failures
Example Response:
{
"success": false,
"message": "Validation failed",
"errors": [
"Name is required",
"allowedIp must be a valid IP address"
]
}
Common validation errors:
- Missing required
name
field - API key name already exists within tenant
- Invalid IP address format in
allowedIp
- Name contains invalid characters
- Description too long (if limits apply)
401 Unauthorized
Authentication credentials are missing or invalid
Example Response:
{
"success": false,
"message": "API Key is missing.",
"errors": [
"Missing x-api-key header"
]
}
Authentication issues:
- Missing
x-api-key
header - Invalid API key value
- Missing
Authorization: Bearer <token>
header - JWT token expired or invalid
- Malformed authentication headers
403 Forbidden
Valid credentials but insufficient permissions to create API keys
Example Response:
{
"success": false,
"message": "Forbidden - Insufficient permissions",
"errors": [
"Cannot create API keys"
]
}
Permission issues:
- User role does not allow API key creation
- Tenant-level API key creation restrictions
- Maximum API key limit reached for tenant
- Cross-tenant API key creation denied
409 Conflict
API key name already exists within the tenant
Example Response:
{
"success": false,
"message": "API key name already exists",
"errors": [
"An API key with this name already exists"
]
}
Conflict scenarios:
- Another API key in the same tenant has the same name
- Case-insensitive name collision
- Concurrent API key creation with same name
Resolution: Choose a different name or update the existing API key
422 Unprocessable Entity
Request violates business rules or system constraints
Example Response:
{
"success": false,
"message": "API key limit exceeded",
"errors": [
"Tenant has reached maximum API key limit of 10"
]
}
Business rule violations:
- Tenant has reached maximum API key limit
- IP address is in a blocked range
- Name violates naming conventions
- Requested permissions not available for tenant tier
- API key creation temporarily disabled for tenant
500 Internal Server Error
Unexpected server error during API key creation
Example Response:
{
"success": false,
"message": "Internal server error",
"errors": [
"Failed to generate API key"
]
}
Possible causes:
- Database connection failure
- API key generation service unavailable
- Cryptographic key generation errors
- Internal workflow failures
Client action: Retry the request or contact support if persistent
Important Security Notes โ
Key Generation โ
- API key values are automatically generated by the system
- Keys follow a secure format (e.g.,
ak_
prefix + random string) - Key values are cryptographically secure and unique
First and Only Display โ
- โ ๏ธ The full API key is only shown once upon creation
- Store the key value securely immediately after creation
- You cannot retrieve the full key value later for security reasons
IP Restrictions โ
- Use
allowedIp
to restrict API key usage to specific IP addresses - Set to
null
or omit for no IP restriction (less secure) - IP restrictions provide an additional security layer
Best Practices โ
Naming Convention โ
- Use descriptive names that indicate purpose
- Include environment (e.g., "Production Web App", "Dev Mobile")
- Avoid generic names like "API Key 1"
Security Recommendations โ
- Set
allowedIp
when possible for enhanced security - Create separate keys for different applications/environments
- Set
isActive: false
initially if key needs approval process - Document the purpose in the
description
field
Key Management โ
- Regularly audit and rotate API keys
- Deactivate unused keys promptly
- Monitor key usage through logs and analytics
- Implement key expiration policies when available
Post-Creation Steps โ
After creating an API key:
- Save the Key: Store the key value in your application's secure configuration
- Test the Key: Verify the key works with a simple API call
- Document Usage: Record where and how the key is being used
- Monitor Access: Set up monitoring for key usage patterns
- Plan Rotation: Schedule regular key rotation for security
Example Usage After Creation โ
bash
# Test the newly created API key
curl -X GET https://shipyo.it/api/User/getAll \
-H "x-api-key: ak_3456789012bcdef3456789012" \
-H "Authorization: Bearer your-jwt-token"