> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firstresonance.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Manage part inventory and kitting

> Create part inventory through the ION API, issue parts to kits to allocate inventory to runs, and move parts back to inventory.

## Inventory

ION tracks parts by serial number or lot number. You can also leave a part untracked and record only its quantity. Part inventory holds information about a part and sets it up so you can track it in runs and aBOM construction.

| Part inventory | Description                                                                                                                                                                                     |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| id             | Unique identifier for a part inventory object.                                                                                                                                                  |
| serialNumber   | Required if the part is serial tracked. Must be unique per part, so another inventory object with the same part relation cannot have a matching serial number. Can optionally be autogenerated. |
| lotNumber      | Required if the part is lot tracked. Can optionally be autogenerated.                                                                                                                           |
| location       | Location where the inventory object is stored.                                                                                                                                                  |
| part           | [Part](/api/guides/parts-and-part-revisioning) that this inventory object is an instance of.                                                                                                    |
| unitOfMeasure  | How the quantity of this inventory object is measured.                                                                                                                                          |
| quantity       | Amount of inventory present.                                                                                                                                                                    |
| runs           | [Runs](/api/guides/runs) related to this inventory object.                                                                                                                                      |
| installed      | `true` if all quantity is attached to aBOM items, otherwise `false`.                                                                                                                            |
| kitted         | `true` if all quantity is kitted to runs, otherwise `false`.                                                                                                                                    |

### Inventory tracking types

| Tracking type |                                                                                                                                                                              |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| serial        | Any inventory with a serial number has the serial tracking type. It can also have a lot number in addition. Serialized inventory objects can only have a quantity of 0 or 1. |
| lot           | Any inventory object with a lot number and no serial number is lot tracked. Lot-tracked items must have a quantity greater than or equal to 0.                               |
| untracked     | If a part inventory has neither a serial nor a lot number, it is an untracked item. There are no quantity restrictions on an untracked part.                                 |

### Query part inventories

List part inventory with a filter:

```graphql theme={null}
query PartInventories($filters: PartInventoriesInputFilters, $sort: [PartInventorySortEnum]) {
    partInventories(sort: $sort, filters: $filters, first: 50) {
        edges {
            node {
                id cost quantity usageType
                part { partNumber }
                location { id }
            }
        }
    }
}
```

Set the filter variables:

```json theme={null}
{
    "filters": {
        "locationId": {
            "eq": 1
        }
    }
}
```

Get a single part inventory record by ID:

```graphql theme={null}
query PartInventory {
    partInventory(id: 1) {
        id cost quantity usageType
        part { partNumber }
        location { id }
    }
}
```

### Create part inventories

When you specify no quantity, the inventory object has a quantity of 0. You can also autogenerate the serial number or lot number.

Create the inventory with this mutation:

```graphql theme={null}
mutation CreatePartInventory($input: CreatePartInventoryInput!) {
    createPartInventory(input: $input) {
        partInventory {
            id quantity cost usageType createdById
            trackingType locationId supplierId _etag
        }
    }
}
```

A serialized part can also belong to a lot, so the input can include a lot number. A serial-tracked part cannot have a quantity greater than 1. Set the variables for a serialized part:

```json theme={null}
{
    "input": {
        "serialNumber": "sn-1",
        "lotNumber": "123",
        "quantity": 1,
        "partId": 1,
        "supplierId": 1,
        "locationId": 5
    }
}
```

Set the variables for a lot-tracked part:

```json theme={null}
{
    "input": {
        "lotNumber": "lot-12",
        "partId": 2,
        "supplierId": 1,
        "locationId": 5
    }
}
```

Autogenerate a serial or lot number with these variables:

```json theme={null}
{
    "input": {
        "autogenerateSerialNumber": true,
        "autogenerateLotNumber": true,
        "lotNumber": "123",
        "quantity": 1,
        "partId": 1,
        "supplierId": 1,
        "locationId": 5
    }
}
```

### Update inventory items

You can change almost all the fields on an inventory object except its relation to the part it is an instance of. All the quantity and tracking-type validations enforced on creation are also enforced on update.

Update the inventory with this mutation:

```graphql theme={null}
mutation UpdatePartInventory($input: UpdatePartInventoryInput!) {
    updatePartInventory(input: $input) {
        partInventory {
            id quantity cost locationId serialNumber lotNumber
        }
    }
}
```

Set the variables:

```json theme={null}
{
    "input": {
        "id": 1,
        "etag": "etag1",
        "lotNumber": "ion-21",
        "cost": 11.21,
        "locationId": 1
    }
}
```

### Delete part inventories

Delete the inventory with this mutation:

```graphql theme={null}
mutation DeletePartInventory($id: ID!, $etag: String!) {
    deletePartInventory(id: $id, etag: $etag) {
        id
    }
}
```

Set the variables:

```json theme={null}
{
    "id": 1,
    "etag": "etag1"
}
```

## Issue parts to runs

### Part kits

Part kits let you allocate specific parts and quantities for a run. To create a part kit, you must already have a run. See the [Runs](/api/guides/runs) example for how to create one.

To remove parts from inventory and attach them to the run that consumes them, use a part kit object.

| Part kits       | Description                                                                                                                        |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| id              | Unique identifier for a part kit object.                                                                                           |
| run             | [Run](/api/guides/runs) that inventory objects are kitted to.                                                                      |
| partInventories | Inventory objects with an additional field, `issuedQuantity`, which identifies the quantity of the inventory allocated to the run. |

Create a kit with this mutation:

```graphql theme={null}
mutation CreatePartKit($input: CreatePartKitInput!) {
    createPartKit(input: $input) {
        partKit {
            id run { id title }
        }
    }
}
```

Set the variables:

```json theme={null}
{
    "input": {
        "runId": 1
    }
}
```

### Issue inventory to kits

To move parts from inventory into the part kit, use the `issueItemToKit` mutation. Whether a part is serial-tracked, lot-tracked, or untracked, you reference its `partInventoryId` and, when the item is not serial-tracked, the `quantity` you want to issue to that kit:

Issue an item to the kit with this mutation:

```graphql theme={null}
mutation IssueItemToKit($input: InventoryToKitInput!) {
    issueItemToKit(input: $input) {
        partInventory {
            id serialNumber partKits { id }
        }
    }
}
```

Set the variables:

```json theme={null}
{
    "input": {
        "partInventoryId": 1,
        "etag": "etag",
        "partKitItemId": 1
    }
}
```

Issuing serials, lots, or untracked parts uses the same `issueItemToKit` mutation. When you issue parts to a kit, the kit shows the quantity of that required part fulfilled as `issuedQuantity`. The quantity is decremented from the original inventory object.

### Move parts back to inventory

Once a serial-tracked part is built, move it back to inventory for use on a higher-level assembly.

Move an item back to inventory with this mutation:

```graphql theme={null}
mutation MoveItemToInventory($input: InventoryToKitInput!) {
    moveItemToInventory(input: $input) {
        partInventory {
           id quantity partId serialNumber lotNumber 
           location { name } partKits { id }
        }
    }
}
```

Set the variables:

```json theme={null}
{
    "input": {
        "quantity": 2,
        "partKitItemId": 1, 
        "etag": "etag",
        "partInventoryId": 3
    }
}
```

You must include the quantity you are moving back to inventory. For a lot-tracked or untracked item, this quantity can be less than the full amount originally issued.

### Query part kits

List part kits with a filter:

```graphql theme={null}
query PartKits($filters: PartKitsInputFilters) {
    partKits(filters: $filters) {
        edges{
            node {
                id
                run { id }
                partInventories { id issuedQuantity }
            }
        }
    }
}
```

Set the filter variables:

```json theme={null}
{
    "filters": {
        "runId": {
            "eq": 1
        }
    }
}
```

## Related

* [Manage parts and revisions](/api/guides/parts-and-part-revisioning)
* [Create a run](/api/guides/runs)
* [Build an aBOM](/api/guides/abom-as-built-bill-of-materials-api)
