Integrate CostTrack Pro with your external systems to automatically trigger sales.
https://costtrack.crudtools.com/apiAll requests require Bearer token authentication using your project's API key.
Authorization: Bearer YOUR_API_KEYproductId
string (UUID) - Required
The UUID of the product being sold. Must exist in your project.
quantity
number - Required
Number of units sold. Must be greater than 0.
sellingPrice
number - Required
Price per unit in the project's currency. Must be greater than 0.
category
string - Optional
Sale category for organization (e.g., "Online Sales", "Retail", "Wholesale").
deductInventory
boolean - Optional (default: false)
Whether to automatically deduct the sold quantity from product inventory. Set to true to update stock levels.
Success (200):
{
"success": true,
"saleId": "550e8400-e29b-41d4-a716-446655440000",
"productId": "550e8400-e29b-41d4-a716-446655440001",
"quantity": 5,
"totalAmount": 12500,
"inventoryDeducted": true
}401 Unauthorized
Invalid or missing API key
404 Not Found
Product does not exist in your project
400 Bad Request
Invalid parameters or insufficient inventory
curl -X POST https://costtrack.crudtools.com/api/sales/create \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"productId": "550e8400-e29b-41d4-a716-446655440000",
"quantity": 5,
"sellingPrice": 2500,
"category": "Online Sales",
"deductInventory": true
}'const response = await fetch('https://costtrack.crudtools.com/api/sales/create', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
productId: '550e8400-e29b-41d4-a716-446655440000',
quantity: 5,
sellingPrice: 2500,
category: 'Online Sales',
deductInventory: true,
}),
});
const result = await response.json();
console.log('Sale created:', result.saleId);import requests
url = 'https://costtrack.crudtools.com/api/sales/create'
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
}
data = {
'productId': '550e8400-e29b-41d4-a716-446655440000',
'quantity': 5,
'sellingPrice': 2500,
'category': 'Online Sales',
'deductInventory': True,
}
response = requests.post(url, json=data, headers=headers)
result = response.json()
print(f"Sale created: {result['saleId']}")• Store API keys securely in environment variables, never hardcode them
• Regenerate keys if they are exposed or compromised
• Use different API keys for different integrations if possible
• Rotate keys periodically for security
• Always check HTTP status codes and handle errors gracefully
• Implement retry logic for transient failures (5xx errors)
• Log all API calls for debugging and auditing
• Validate product IDs before sending requests
• Set deductInventory to true only when you want to update stock
• Verify sufficient inventory before creating sales
• Monitor inventory levels to prevent overselling
• Use categories to organize sales by channel
• Test with deductInventory: false first before enabling updates
• Use meaningful category names for easy filtering
• Implement idempotency to prevent duplicate sales
• Monitor API response times and optimize batch operations