# Edit Item

## Endpoint

<mark style="color:purple;">**`PUT`**</mark> `https://api.xtrakit.com/api/v1/inventory/items/{item_code}`

## Headers

`Authorization: Bearer API_KEY`

## **Path Parameters**

<table><thead><tr><th>Parameters</th><th width="100">Type</th><th>Description</th></tr></thead><tbody><tr><td><p>item_code</p><p><em><strong>string</strong></em></p></td><td>Required</td><td>The unique code for identifying the item in the inventory system. Should be passed through the URL.(<code>Jce84a50)</code></td></tr></tbody></table>

## Body Parameters

<table><thead><tr><th>Parameters</th><th width="100">Type</th><th>Description</th></tr></thead><tbody><tr><td><p>item_name</p><p><em><strong>string</strong></em></p></td><td>Required</td><td>The name or title of the item.</td></tr><tr><td><p>category_id</p><p><em><strong>int</strong></em></p></td><td>Required</td><td>The ID representing the category this item belongs to.</td></tr><tr><td><p>unit</p><p><em><strong>string</strong></em></p></td><td>Required</td><td><p>The unit of measure for the item.</p><p><code>(pcs, kg, liters,...)</code></p></td></tr><tr><td><p>description</p><p><em><strong>string</strong></em></p></td><td>Optional</td><td>A detailed description of the item, providing more information about its features.</td></tr><tr><td><p>unit_cost</p><p><em><strong>decimal(10,2)</strong></em></p></td><td>Required</td><td>The cost price of a single unit of the item in this format: <code>10.00</code></td></tr><tr><td><p>item_price</p><p><em><strong>decimal(10,2)</strong></em></p></td><td>Required</td><td>The selling price of the item in this format: <code>10.00</code></td></tr><tr><td><p>previous_price</p><p><em><strong>decimal(10,2)</strong></em></p></td><td>Optional</td><td>The previous selling price of the item in this format: <code>10.00</code></td></tr><tr><td><p>quantity</p><p><em><strong>string</strong></em></p></td><td>Required</td><td>The available stock or quantity of the item.</td></tr><tr><td><p>minimum_qty_alert</p><p><em><strong>string</strong></em></p></td><td>Optional</td><td>A threshold quantity that triggers an alert when stock falls below this level.</td></tr><tr><td><p>online</p><p>int</p></td><td>Required</td><td><p>Indicator whether the item is available online. </p><p><code>Accepts 1 (true) or 0 (false)</code></p></td></tr><tr><td><p>status</p><p><em><strong>string</strong></em></p></td><td>Required</td><td><p>The availability status of the item. </p><p><code>(available, out of stock).</code></p></td></tr><tr><td><p>barcode</p><p>string</p></td><td>Optional</td><td>The barcode assigned to the item.</td></tr><tr><td><p>sku</p><p><em><strong>string</strong></em></p></td><td>Optional</td><td>The Stock Keeping Unit (SKU) for tracking inventory.</td></tr><tr><td><p>warehouse_id</p><p>int</p></td><td>Optional</td><td>The ID of the warehouse where the item is stored.</td></tr><tr><td><p>item_location</p><p><em><strong>string</strong></em></p></td><td>Optional</td><td>The physical location of the item within the warehouse.</td></tr><tr><td><p>item_slug</p><p><em><strong>string</strong></em></p></td><td>Optional</td><td>A URL-friendly version of the item name used in links and routes.</td></tr></tbody></table>

## Sample Requests <a href="#sample-requests" id="sample-requests"></a>

{% tabs %}
{% tab title="PHP" %}
{% code fullWidth="true" %}

```php
<?php
$item_code = 'YOUR_ITEM_CODE'; // Replace 'YOUR_ITEM_CODE' with your actual item code

$data = [
  'item_name' => "Recliner Sofa", 
  'category_id' => 2, 
  'unit' => "kg", 
  'description' => "Sofa with one or more seats that recline like a recliner chair.", 
  'unit_cost' => 300.00, 
  'item_price' => 450.00, 
  'previous_price' => 350.00, 
  'quantity' => "50", 
  'minimum_qty_alert' => "5", 
  'online' => 1, 
  'status' => "in-stock", 
  'barcode' => "YOUR ITEM BARCODE",  // Replace 'YOUR ITEM BARCODE' with your actual item barcode
  'sku' => "TABLE001",
  'warehouse_id' => 2,
  'item_location' => "A1",
  'item_slug' => "table"
];

$url = 'https://api.xtrakit.com/api/v1/inventory/items/' . $item_code;

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => $url,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'PUT',
  CURLOPT_POSTFIELDS => $data,
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer API_KEY', // Replace 'API_KEY' with your actual API key
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

?>
```

{% endcode %}
{% endtab %}

{% tab title="NodeJS" %}

```javascript
const axios = require('axios');

const item_code = 'YOUR_ITEM_CODE'; // Replace 'YOUR_ITEM_CODE' with your actual item code

const data = {
  'item_name': "Recliner Sofa", 
  'category_id': 2, 
  'unit': "kg", 
  'description': "Sofa with one or more seats that recline like a recliner chair.", 
  'unit_cost': 300.00, 
  'item_price': 450.00, 
  'previous_price': 350.00, 
  'quantity': "50", 
  'minimum_qty_alert': "5", 
  'online': 1, 
  'status': "in-stock", 
  'barcode': "YOUR ITEM BARCODE",  // Replace 'YOUR ITEM BARCODE' with your actual item barcode
  'sku': "TABLE001",
  'warehouse_id': 2,
  'item_location': "A1",
  'item_slug': "table"
};

const config = {
    method: 'put',
    url: `https://api.xtrakit.com/api/v1/inventory/items/{item_code}`,
    headers: {
        'Authorization': 'Bearer API_KEY' // Replace 'API_KEY' with your actual API key
    },
    data: data 
};

axios(config).then(function(response) {
    console.log(JSON.stringify(response.data));
}).catch(function(error) {
    console.error(error);
});

```

{% endtab %}

{% tab title="Python" %}

```python
import requests

item_code = 'YOUR_ITEM_CODE' # Replace 'YOUR_ITEM_CODE' with your actual item code

data = {
  'item_name': "Recliner Sofa", 
  'category_id': 2, 
  'unit': "kg", 
  'description': "Sofa with one or more seats that recline like a recliner chair.", 
  'unit_cost': 300.00, 
  'item_price': 450.00, 
  'previous_price': 350.00, 
  'quantity': "50", 
  'minimum_qty_alert': "5", 
  'online': 1, 
  'status': "in-stock", 
  'barcode': "YOUR ITEM BARCODE",  # Replace 'YOUR ITEM BARCODE' with your actual item barcode
  'sku': "TABLE001",
  'warehouse_id': 2,
  'item_location': "A1",
  'item_slug': "table"
}

url = f'https://api.xtrakit.com/api/v1/inventory/items/{item_code}'

headers = {
    "Authorization": "Bearer API_KEY" # Replace 'API_KEY' with your actual API key
}

try:
    response = requests.put(url, headers=headers, json=data)
    print(response.json())
except requests.exceptions.RequestException as e:
    print(e)
```

{% endtab %}
{% endtabs %}

## Sample Response

{% tabs %}
{% tab title="Success" %}

```json
{
    "status": 200,
    "message": "Item updated successfully",
    "data": {
        "item": {
            "id": 2,
            "item_code": "Jce84a60",
            "item_name": "Recliner Sofa",
            "category_id": 2,
            "unit": "kg",
            "description": "Sofa with one or more seats that recline like a recliner chair.",
            "unit_cost": 300.00,
            "item_price": 450.00,
            "previous_price": 250.00,
            "quantity": "50",
            "minimum_qty_alert": "5",
            "online": 1,
            "status": "in-stock",
            "barcode": null,
            "sku": "TABLE001",
            "warehouse_id": 2,
            "item_location": "A1",
            "item_slug": "table",
            "created_at": "2024-08-04 08:23:45",
            "updated_at": "2024-08-04 02:00:43"
        },
        "item-category": [  
            {
                "id": 2,
                "category_name": "Furnitures",
                "created_at": "2024-08-04 08:23:45",
                "updated_at": "2024-08-04 02:00:43",
            },
            ...
        ],
    }
}
```

{% endtab %}

{% tab title="Error" %}

```json
{
    "status": 401,
    "error": "Authentication invalid"
},

{
    "status": 401,
    "error": "Unauthorized: Invalid API Key"
}
```

{% endtab %}
{% endtabs %}
