Returns a product's details, its stock at a storage location and its components.

```
v2/products/get_entry.php
```

## Parameters

| Field | Type | Required | Description |
|---|---|---|---|
| product_id | int | Yes | Product ID |
| storage_id | int | Yes | Storage location ID |

The product is returned only if it is stocked at storage location storage_id. Stock across all storage locations at once is returned by [v1/products/get_stocks](https://developers.controlata.com/hc/api-docs/articles/api-products-get-stocks).

## Response

An object product with the product's fields, its stock at storage location storage_id, its categories, suppliers, alternative SKUs and components.

| Field | Type | Description |
|---|---|---|
| id | int | Product ID |
| name | string | Name |
| sku | string | SKU |
| unit | string | Unit of measure, a code from [Units of Measure](https://developers.controlata.com/hc/api-docs/articles/api-units-get-list) |
| price | float | Sale price per unit |
| cost | float | Cost per unit |
| batch_size | float | Batch size: the product quantity the components are given for |
| notes | string | Notes |
| archived | int | 1 if the product is archived |
| stock | float | Stock at storage location storage_id |
| minimum | float | Minimum stock at storage location storage_id |
| planned | float | Stock change from operations in the Planned status. null if there are none |
| categories | array | The product's categories: objects with id and name |
| suppliers | array | The product's suppliers: objects with id and name |
| alternative_sku | array | Alternative SKUs: objects with label and sku |

Besides these fields, the object holds the components:

| Field | Type | Description |
|---|---|---|
| materials | array | Materials in the components |
| products | array | Subassemblies in the components |
| resources | array | Resources in the components |

Fields of the materials, products and resources lines:

| Field | Description |
|---|---|
| id | Material, product or resource ID |
| name | Name |
| sku | SKU. Materials and subassemblies only |
| type | Resource calculation type. Resources only (see [Creating a Resource](https://developers.controlata.com/hc/api-docs/articles/api-resources-add)) |
| dynamic | 1 if the price or percentage is specified in the product components. Resources only |
| base | Calculation basis of a percentage resource: cost or price. Resources only |
| amount_per_batch | Quantity per batch |
| amount_per_unit | Quantity per product unit: amount_per_batch / batch_size |
| loss_percent | Loss, in percent. Materials and subassemblies only |
| unit | Unit of measure. "%" for a percentage resource |
| cost_per_unit | Line cost per product unit |
| cost_per_batch | Line cost per batch |
| position | Line position: shared by materials and products, separate for resources |

For a resource of the fixed-rate type with its price in the product components, amount_per_batch holds a money amount, not a quantity.

cost_per_unit and cost_per_batch account for loss when loss_percent > 0.

The component lines, categories and suppliers from the response can be sent to [v1/products/edit](https://developers.controlata.com/hc/api-docs/articles/api-products-edit) unchanged.

## Example request

```
{
    "product_id": 3120,
    "storage_id": 3999
}
```

## Example response

```
{
    "success": true,
    "product": {
        "id": 3120,
        "name": "Dining table",
        "sku": "P100",
        "price": 45000,
        "cost": 13604.25,
        "batch_size": 10,
        "notes": "",
        "archived": 0,
        "stock": 12,
        "minimum": 3,
        "planned": null,
        "unit": "pcs",
        "categories": [
            {
                "id": 21,
                "name": "Furniture"
            }
        ],
        "alternative_sku": [
            {
                "label": "Shopify",
                "sku": "SH-P100"
            }
        ],
        "suppliers": [
            {
                "id": 46,
                "name": "Furnitrade Ltd"
            }
        ],
        "materials": [
            {
                "id": 2051,
                "name": "Oak board",
                "sku": "M010",
                "amount_per_unit": 0.05,
                "amount_per_batch": 0.5,
                "loss_percent": 5,
                "unit": "cu m",
                "cost_per_unit": 7087.5,
                "cost_per_batch": 70875,
                "position": 0
            },
            {
                "id": 2060,
                "name": "Wood screw 4x40",
                "sku": "M024",
                "amount_per_unit": 40,
                "amount_per_batch": 400,
                "loss_percent": 0,
                "unit": "pcs",
                "cost_per_unit": 80,
                "cost_per_batch": 800,
                "position": 1
            }
        ],
        "products": [
            {
                "id": 312,
                "name": "Table leg",
                "sku": "P012",
                "amount_per_unit": 4,
                "amount_per_batch": 40,
                "loss_percent": 0,
                "unit": "pcs",
                "cost_per_unit": 3400,
                "cost_per_batch": 34000,
                "position": 2
            }
        ],
        "resources": [
            {
                "id": 57,
                "name": "Carpenter's work",
                "type": "rate",
                "dynamic": 0,
                "base": null,
                "amount_per_unit": 3,
                "amount_per_batch": 30,
                "unit": "h",
                "cost_per_unit": 1800,
                "cost_per_batch": 18000,
                "position": 0
            },
            {
                "id": 58,
                "name": "Overhead",
                "type": "percent",
                "dynamic": 0,
                "base": "cost",
                "amount_per_unit": 10,
                "amount_per_batch": 10,
                "unit": "%",
                "cost_per_unit": 1236.75,
                "cost_per_batch": 12367.5,
                "position": 1
            }
        ]
    }
}
```

## Errors

| Error | Reason |
|---|---|
| No product_id in input | A required field is missing (instead of product_id, the field's name) |
| Storage ID not found | Storage location not found or deleted |
| Product not found or access denied | Product not found, deleted or not stocked at the storage location |

## Version v1

The v1/products/get_entry method accepts the same parameters and returns the same product fields. Only the components are represented differently, so use v2 in new integrations.

| What | v1 | v2 |
|---|---|---|
| Components | A single components array: materials and subassemblies together | Separate materials, products and resources arrays |
| id in component lines | Prefixed: "m-123" for a material, "p-45" for a subassembly | Numeric item id |
| Sending lines back to add and edit | Not possible as is, the prefixed ids get in the way | Possible as is |

Besides, v1 returns internal fields that v2 omits: product.status and the status of component lines (always 1) and product.percent (computed from cost and price).
