Diamond Stock — API Documentation

Integrate live diamond inventory and orders into your website

Authentication

All endpoints require your API Key in the X-API-Key request header.

X-API-Key: dsm_your_api_key_here

Your API key is provided by the stock manager. Keep it secret — it gives access to your company's orders.

Base URL

https://www.diamond.codimai.com

Stock

GET /api/public/stock.php List available diamonds
ParameterTypeDescription
pageintegerPage number (default: 1)
page_sizeintegerResults per page, max 200 (default: 50)
shapestringFilter by shape e.g. Round
colorstringFilter by color e.g. D
claritystringFilter by clarity e.g. VS1
carat_minfloatMinimum carat weight
carat_maxfloatMaximum carat weight
total_price_minfloatMinimum total price (USD)
total_price_maxfloatMaximum total price (USD)
labstringFilter by lab e.g. GIA, IGI
{
  "total": 120,
  "page": 1,
  "page_size": 50,
  "items": [
    {
      "id": 1,
      "status": "available",
      "data": {
        "stone_id": "DIA-001",
        "shape": "Round",
        "carat": 1.52,
        "color": "D",
        "clarity": "VS1",
        "cut": "Excellent",
        "lab": "GIA",
        "total_price": 8500,
        "image_urls": ["https://example.com/img/dia001.jpg"],
        "video_urls": []
      }
    }
  ]
}
Response will appear here...
GET /api/public/stock.php?id={diamond_id} Single diamond detail

Returns full details of a single available diamond by its ID.

Response will appear here...

Orders

POST /api/public/orders.php Place an order

Place an order for one or more diamonds. Selected diamonds are automatically placed on hold. The hold expires if not confirmed by the stock manager.

Company details are auto-filled from your API key. You only need to send items. Contact name, email, phone, and company name are pulled automatically from your registered account.

FieldRequiredDescription
itemsYesArray of {"diamond_id": N} objects (max 50)
noteNoOrder note or delivery instructions
customer_nameNoOverride contact name for this order (defaults to your registered contact person)
customer_emailNoOverride email for this order (defaults to your registered email)
customer_phoneNoOverride phone for this order (defaults to your registered phone)
// Minimal request — company info auto-filled from API key
{
  "items": [
    { "diamond_id": 1 },
    { "diamond_id": 5 }
  ],
  "note": "Please deliver by Friday"
}

// Response (201 Created)
{
  "id": 42,
  "status": "pending",
  "customer_name": "Rajesh Shah",       // from your registered contact
  "customer_company": "Shah Jewellers", // from your registered company name
  "customer_email": "rajesh@example.com",
  "customer_phone": "+91 98765 43210",
  "total_amount": 15200,
  "items": [ ... ],
  "created_at": "2024-01-15T10:30:00"
}
Response will appear here...
GET /api/public/orders.php List your orders

Returns only orders placed by your API key. Optional ?status=pending|confirmed|shipped|cancelled filter.

Response will appear here...
GET /api/public/orders.php?id={order_id} Single order detail

Returns full detail of one of your orders including all diamond snapshots.

Order Status Flow

pending confirmed shipped

Order starts as pending — diamonds are put on hold. The stock manager confirms → confirmed, then ships → shipped. Either party can cancel at any stage.

JavaScript Quick Start

const API_KEY = 'dsm_your_key_here';
const BASE    = 'https://www.diamond.codimai.com';

// Browse available diamonds
async function getStock(page = 1) {
  const r = await fetch(`${BASE}/api/public/stock.php?page=${page}&page_size=20`, {
    headers: { 'X-API-Key': API_KEY }
  });
  return r.json(); // { total, page, page_size, items: [...] }
}

// Place an order — company info is auto-filled from your API key
async function placeOrder(diamondIds, note = '') {
  const r = await fetch(`${BASE}/api/public/orders.php`, {
    method:  'POST',
    headers: { 'X-API-Key': API_KEY, 'Content-Type': 'application/json' },
    body:    JSON.stringify({
      items: diamondIds.map(id => ({ diamond_id: id })),
      note
    })
  });
  return r.json();
}