Sales API Documentation

Integrate CostTrack Pro with your external systems to automatically trigger sales.

API Overview
The CostTrack Pro Sales API allows external systems (e-commerce platforms, order management systems, ERPs) to trigger sales directly in CostTrack Pro. Each sale includes product ID, quantity, selling price, and optional inventory deduction.

Base URL

https://costtrack.crudtools.com/api

Authentication

All requests require Bearer token authentication using your project's API key.

Authorization: Bearer YOUR_API_KEY

Endpoints

Create Sale
POST /sales/create

Request Parameters

productId

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.

Response

Success (200):

{ "success": true, "saleId": "550e8400-e29b-41d4-a716-446655440000", "productId": "550e8400-e29b-41d4-a716-446655440001", "quantity": 5, "totalAmount": 12500, "inventoryDeducted": true }

Error Responses

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

Code Examples

cURL
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
  }'
JavaScript
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);
Python
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']}")

Best Practices

API Key Security

• 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

Error Handling

• 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

Inventory Management

• 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

Integration Tips

• 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

Need Help?

For API support, contact our team or check the main documentation.