POST 5 min read

Import Parts

POST /api/v1/parts/import

Bulk import parts into your inventory

Import Parts

Bulk import multiple parts into your inventory. This endpoint uses upsert logic - parts with matching SKU or part number will be updated, new parts will be created.

Request Body

Field Type Required Description
company_id integer Yes The company to import parts to
parts array Yes Array of parts to import (1-500 items)

Part Object

Field Type Required Description
name string Yes Part name (max 255 chars)
part_number string No Manufacturer part number (max 100 chars)
sku string No Stock keeping unit (max 100 chars)
description string No Part description
category string No Part category (max 100 chars)
brand string No Brand name (max 100 chars)
cost_price number No Cost price (min 0)
selling_price number No Selling price (min 0)
quantity_in_stock integer No Current stock quantity (min 0)
reorder_level integer No Low stock threshold (min 0)
unit string No Unit of measure (max 20 chars)

Example Request

curl -X POST "https://hydra.marketdragon.ph/api/v1/parts/import" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "company_id": 1,
    "parts": [
      {
        "name": "Oil Filter - Standard",
        "part_number": "OF-001",
        "sku": "SKU-OF-001",
        "category": "Filters",
        "brand": "FilterPro",
        "cost_price": 120.00,
        "selling_price": 200.00,
        "quantity_in_stock": 100,
        "reorder_level": 20,
        "unit": "pcs"
      },
      {
        "name": "Oil Filter - Premium",
        "part_number": "OF-002",
        "sku": "SKU-OF-002",
        "category": "Filters",
        "brand": "FilterPro",
        "cost_price": 180.00,
        "selling_price": 300.00,
        "quantity_in_stock": 50,
        "reorder_level": 10,
        "unit": "pcs"
      },
      {
        "name": "Air Filter",
        "part_number": "AF-001",
        "sku": "SKU-AF-001",
        "category": "Filters",
        "brand": "AirFlow",
        "cost_price": 80.00,
        "selling_price": 150.00,
        "quantity_in_stock": 75,
        "reorder_level": 15,
        "unit": "pcs"
      }
    ]
  }'

Example Response

{
    "message": "Successfully imported 3 parts.",
    "imported": 3,
    "errors": []
}

Response with Errors

If some parts fail to import, you'll receive partial success:

{
    "message": "Successfully imported 2 parts.",
    "imported": 2,
    "errors": [
        {
            "index": 2,
            "name": "Air Filter",
            "error": "Duplicate entry for key 'parts_sku_unique'"
        }
    ]
}

Upsert Behavior

Parts are matched by the combination of:

  • company_id + sku
  • company_id + part_number

If a match is found, the existing part is updated. Otherwise, a new part is created.

Limits

  • Maximum 500 parts per request
  • All imported parts are automatically set to is_active: true

Error Responses

403 Forbidden

{
    "message": "You do not have access to this company."
}

422 Validation Error

{
    "message": "The parts field is required.",
    "errors": {
        "parts": ["The parts field is required."],
        "parts.0.name": ["The parts.0.name field is required."]
    }
}
Back to Parts
Was this helpful?