# Product API

## Get Products (Catalog)

Retrieve product catalog for an organization.

**Endpoint:** `POST https://api.quick.myquickapp.com/inventory/getproducts`

### Request Headers

```
Authorization: Bearer {api_key}
Content-Type: application/json
language: en
```

### Request Body

```json
{
  "org_id": "12345"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Headers": "*",
    "Access-Control-Allow-Methods": "OPTIONS,POST,GET"
  },
  "body": {
    "products": [
      {
        "id": 101,
        "name": "Product Name",
        "description": "Product description",
        "price": 99.99,
        "cost": 50.00,
        "category": "Electronics",
        "stock": 100,
        "sku": "PROD-001",
        "barcode": "1234567890123",
        "image": "https://s3-url-here.com/image.jpg",
        "taxable": true,
        "tax_rate": 15.0,
        "type": "inventory",
        "uom": "Each",
        "created_at": "2024-01-15T10:30:00",
        "updated_at": "2024-01-20T14:45:00"
      }
    ],
    "pagination": {
      "page_number": 1,
      "page_size": 25,
      "total_items": 100,
      "total_pages": 4,
      "has_next": true,
      "has_previous": false
    }
  }
}
```

---

## Create Product

Create a new product in the catalog.

**Endpoint:** `POST https://api.quick.myquickapp.com/inventory/editproduct/`

### Request Headers

```
Authorization: Bearer {api_key}
Content-Type: application/json
language: en
```

### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "name": "New Product",
  "description": "Product description",
  "price": 99.99,
  "cost": 50.00,
  "category_id": "cat_123",
  "sku": "PROD-001",
  "barcode": "1234567890123",
  "taxable": true,
  "tax_rate": 15.0,
  "type": "inventory",
  "uom": "Each",
  "stock": 100,
  "warehouse_id": "wh_1",
  "location_id": "loc_1"
}
```

### Response - Success (200)

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Product created successfully",
    "product": {
      "id": 201,
      "name": "New Product",
      "description": "Product description",
      "price": 99.99,
      "cost": 50.00,
      "category_id": "cat_123",
      "sku": "PROD-001",
      "barcode": "1234567890123",
      "taxable": true,
      "tax_rate": 15.0,
      "type": "inventory",
      "uom": "Each",
      "stock": 100,
      "created_at": "2024-03-10T10:00:00"
    }
  }
}
```

### Response - Error (400)

```json
{
  "statusCode": 400,
  "headers": {...},
  "body": {
    "message": "SKU already exists"
  }
}
```

---

## Edit Product

Update an existing product.

**Endpoint:** `POST https://api.quick.myquickapp.com/inventory/editproduct/`

### Request Headers

```
Authorization: Bearer {api_key}
Content-Type: application/json
language: en
```

### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "product_id": 201,
  "name": "Updated Product Name",
  "description": "Updated description",
  "price": 109.99,
  "cost": 55.00,
  "category_id": "cat_456",
  "sku": "PROD-001-UPD",
  "barcode": "1234567890123",
  "taxable": true,
  "tax_rate": 15.0,
  "type": "inventory",
  "uom": "Each",
  "stock": 150
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Product updated successfully",
    "product": {
      "id": 201,
      "name": "Updated Product Name",
      "description": "Updated description",
      "price": 109.99,
      "cost": 55.00,
      "category_id": "cat_456",
      "sku": "PROD-001-UPD",
      "barcode": "1234567890123",
      "taxable": true,
      "tax_rate": 15.0,
      "type": "inventory",
      "uom": "Each",
      "stock": 150,
      "updated_at": "2024-03-10T11:30:00"
    }
  }
}
```

---

## Delete Product

Delete a product from the catalog.

**Endpoint:** `POST https://api.quick.myquickapp.com/inventory/editproduct/`

### Request Headers

```
Authorization: Bearer {api_key}
Content-Type: application/json
language: en
```

### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "product_id": 201,
  "delete": true
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Product deleted successfully"
  }
}
```

---

## Product Categories

### Create Product Category

**Endpoint:** `POST https://api.quick.myquickapp.com/inventory/categories`

#### Request Headers

```
Authorization: Bearer {api_key}
Content-Type: application/json
language: en
```

#### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "name": "Electronics",
  "code": "ELEC",
  "parent_id": null,
  "taxable": true,
  "default_account": "sales_101"
}
```

#### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Category created successfully",
    "category": {
      "id": "cat_789",
      "name": "Electronics",
      "code": "ELEC",
      "parent_id": null,
      "taxable": true,
      "default_account": "sales_101"
    }
  }
}
```

### Edit Product Category

#### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "category_id": "cat_789",
  "name": "Electronics & Gadgets",
  "code": "ELEC-GAD",
  "taxable": true,
  "default_account": "sales_102"
}
```

#### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Category updated successfully",
    "category": {
      "id": "cat_789",
      "name": "Electronics & Gadgets",
      "code": "ELEC-GAD",
      "taxable": true,
      "default_account": "sales_102"
    }
  }
}
```

---

## Stock Management

### Get Product Stock Details

**Endpoint:** `POST https://api.quick.myquickapp.com/inventory/ops/getdata`

#### Request Headers

```
Authorization: Bearer {api_key}
Content-Type: application/json
language: en
```

#### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "stock_details",
  "product_id": 201
}
```

#### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "product_id": 201,
    "product_name": "Updated Product Name",
    "current_stock": 150,
    "stock_details": [
      {
        "warehouse_id": "wh_1",
        "warehouse_name": "Main Warehouse",
        "location_id": "loc_1",
        "location_name": "Aisle 1",
        "stock_quantity": 100
      },
      {
        "warehouse_id": "wh_2",
        "warehouse_name": "Secondary Warehouse",
        "location_id": "loc_2",
        "location_name": "Aisle 2",
        "stock_quantity": 50
      }
    ],
    "min_stock_level": 20,
    "max_stock_level": 500,
    "last_stock_check": "2024-03-10T10:00:00"
  }
}
```

### Adjust Stock

#### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "stock_adjustment",
  "product_id": 201,
  "qty_locations": {
    "loc_1": 120,
    "loc_2": 60
  },
  "adjustment_type": "increase",
  "reference": "Stock count correction",
  "notes": "Adjusted based on physical count"
}
```

#### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Stock adjusted successfully",
    "stock_move_id": "move_12345",
    "details": [
      {
        "location_id": "loc_1",
        "previous_stock": 100,
        "new_stock": 120,
        "change": 20
      },
      {
        "location_id": "loc_2",
        "previous_stock": 50,
        "new_stock": 60,
        "change": 10
      }
    ]
  }
}
```

---

## Variant Management

### Create Product Variant

**Endpoint:** `POST https://api.quick.myquickapp.com/inventory/editproduct/`

#### Request Headers

```
Authorization: Bearer {api_key}
Content-Type: application/json
language: en
```

#### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "create_variant",
  "parent_product_id": 201,
  "variant_name": "Red Color",
  "options": {
    "color": "Red",
    "size": "Medium"
  },
  "price": 119.99,
  "cost": 60.00,
  "sku": "PROD-001-R-M",
  "barcode": "1234567890124"
}
```

#### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Variant created successfully",
    "variant": {
      "id": 202,
      "parent_product_id": 201,
      "variant_name": "Red Color",
      "options": {
        "color": "Red",
        "size": "Medium"
      },
      "price": 119.99,
      "cost": 60.00,
      "sku": "PROD-001-R-M",
      "barcode": "1234567890124"
    }
  }
}
```
