API Overview

Getting started with the CostSync API

Last updated: 17th January 2025

API Overview

The CostSync API provides programmatic access to your cost and profit data.

Authentication

Getting Your API Key

  1. Go to Settings > API in CostSync
  2. Click Generate API Key
  3. Copy and securely store your key
⚠️
Warning

Keep your API key secure. Never expose it in client-side code or public repositories.

Using Your API Key

Include your API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY

Available Endpoints

Products

MethodEndpointDescription
GET/productsList all products
GET/products/:idGet a single product
PUT/products/:id/costUpdate product cost

Orders

MethodEndpointDescription
GET/ordersList orders with profit
GET/orders/:idGet order details

Suppliers

MethodEndpointDescription
GET/suppliersList all suppliers
POST/suppliersCreate a supplier
PUT/suppliers/:idUpdate a supplier

Reports

MethodEndpointDescription
GET/reports/profitGet profit report
GET/reports/productsGet product performance

Response Format

All responses are JSON formatted:

{
  "success": true,
  "data": {
    // Response data here
  },
  "meta": {
    "page": 1,
    "per_page": 50,
    "total": 150
  }
}

Error Handling

Errors return appropriate HTTP status codes:

CodeMeaning
400Bad request - check your parameters
401Unauthorized - check your API key
403Forbidden - insufficient permissions
404Not found - resource doesn't exist
429Rate limited - slow down requests
500Server error - contact support

Error response format:

{
  "success": false,
  "error": {
    "code": "INVALID_PARAMETER",
    "message": "The 'product_id' parameter is required"
  }
}

Pagination

List endpoints support pagination:

GET /products?page=2&per_page=50

Need Help?