# Create an inventory operation

Creates an inventory document and its product lines in one request. Supported types are 1 (product sale), 3 (product receipt) and 4 (product write-off); 2 (consumption) and 5 (transfer) are refused with 422.
- A Team Member is required for every type, but only a sale keeps it, together with the client, on its lines. A receipt keeps `supplier_id` on its lines.
- `document.comment` becomes the comment of the document and of every line.
- Send `date` as `YYYY-MM-DD HH:MM:SS` in the Location timezone. A value in another format is ignored and the current Location time is used.
- With `paid` and `account_id`, payment transactions are created for the lines; without them no financial transaction is created.

To undo an operation, delete its document with [Delete document](#tag/Inventory/operation/delete_document): the lines are deleted and the stock comes back.

Endpoint: POST /storage_operations/operation/{location_id}
Version: 1.0.0
Security: BearerPartnerUser

## Security:

  - `BearerPartnerUser` (unknown)
    http bearer Bearer {PartnerToken}, User {UserToken}

## Path parameters:

  - `location_id` (number, required)
    location ID

## Header parameters:

  - `Accept` (string, required)
    e.g. application/vnd.api.v2+json

  - `Content-Type` (string, required)
    application/json

  - `Authorization` (string, required)
    Bearer partner_token, User user_token

## Request fields (application/json):

  - `type_id` (integer, required)
    Operation type: 1 product sale, 3 product receipt, 4 product write-off. Any other value, including 2 (consumption) and 5 (transfer), is refused with 422.
    Enum: "1", "3", "4"

  - `storage_id` (integer, required)
    Inventory ID

  - `team_member_id` (integer, required)
    ID of the Team Member who performs the operation. Required for every type; a dismissed Team Member is refused. Only a sale stores it on its lines. The legacy name `master_id` is also accepted.

  - `date` (string)
    Operation date in the Location timezone as `YYYY-MM-DD HH:MM:SS`. Defaults to the current Location time. A value in another format is ignored and the current Location time is used. A date more than five minutes ahead of the current Location time is refused with 400.

  - `document` (object)
    Document parameters

  - `document.comment` (string)
    Document comment. It is also stored as the comment of every line.

  - `client` (object)
    Client of a sale. Pass the `id` of a Location client, or contact details to find or create one.

  - `client.id` (integer)
    Client ID

  - `client.name` (string)
    Client name

  - `client.phone` (string)
    Client phone number

  - `client.email` (string)
    Client email

  - `paid` (boolean)
    When `true`, payment transactions for the lines are created on the cash register `account_id`. Without it no financial transaction is created.

  - `account_id` (integer)
    Cash register ID for the payment. Used with `paid`.

  - `goods_transactions` (array, required)
    Product lines of the operation

  - `goods_transactions.good_id` (integer, required)
    Product ID. Inside this array only `good_id` is read; `product_id` is refused with 422.

  - `goods_transactions.amount` (number, required)
    Quantity, greater than 0. The operation type sets the direction of the stock movement.

  - `goods_transactions.unit_id` (integer)
    Unit ID. Defaults to the sale unit of the product. Pass the service unit to count the quantity in service units.

  - `goods_transactions.operation_unit_type` (integer)
    Unit the quantity is counted in: 1 sale unit, 2 service unit. Derived from `unit_id` when omitted.
    Enum: "1", "2"

  - `goods_transactions.cost_per_unit` (number)
    Price per unit

  - `goods_transactions.discount` (number)
    Discount in %, from 0 to 100

  - `goods_transactions.cost` (number)
    Total line amount. Stored as sent, not computed from the price, quantity and discount.

  - `goods_transactions.supplier_id` (integer)
    Supplier ID from [List Location Suppliers](#tag/Financial-Transactions-and-Accounts/operation/list_location_suppliers). Stored for a receipt only.

  - `goods_transactions.good_special_number` (string)
    Membership or gift card code when the product sells one

## Response 200:

  - `200` (unknown)
    OK

## Response 200 fields (application/json):

  - `success` (boolean)
    Execution success status (true)

  - `data` (object)
    Object with data

  - `data.user_id` (integer)
    ID of the Business User who created the operation

  - `data.company_id` (integer)
    location ID

  - `data.document_id` (integer)
    Document ID. Use it to read the lines or to delete the operation.

  - `data.type_id` (integer)
    Operation type: 1 product sale, 3 product receipt, 4 product write-off

  - `data.master_id` (integer)
    Team Member ID taken from the sale lines; 0 for a receipt or a write-off

  - `data.client_id` (integer)
    Client ID of a sale; 0 when there is none

  - `data.storage_id` (integer)
    Inventory ID

  - `data.date` (string)
    Operation date in the Location timezone as `YYYY-MM-DD HH:MM:SS`

  - `data.account_id` (integer)
    Cash register ID of the payment; 0 when unpaid

  - `data.paid` (boolean)
    Whether the operation has payment transactions

  - `data.document` (object)
    Object with data

  - `data.document.id` (number)
    Document ID

  - `data.document.type_id` (number)
    Document type identifier

  - `data.document.type` (object)
    Document type

  - `data.document.type.id` (number)
    Document type identifier

  - `data.document.type.title` (string)
    Document type name

  - `data.document.storage_id` (number)
    Inventory ID

  - `data.document.user_id` (number)
    User ID

  - `data.document.company_id` (number)
    location ID

  - `data.document.number` (number)
    Document Number

  - `data.document.comment` (string)
    A comment

  - `data.document.create_date` (string)
    Document date in the Location timezone as `YYYY-MM-DD HH:MM:SS`

  - `data.document.bill_print_status` (number)
    Bill print status

  - `data.document.storage` (object)
    Inventory

  - `data.document.storage.id` (number)
    Inventory ID

  - `data.document.storage.title` (string)
    Inventory name

  - `data.document.company` (object)
    location

  - `data.document.company.id` (number)
    location ID

  - `data.document.company.title` (string)
    location name

  - `data.document.company.public_title` (string)
    Public-facing location name

  - `data.document.company.business_group_id` (number)
    Business group ID

  - `data.document.company.business_type_id` (number)
    Business type ID

  - `data.document.company.country_id` (number)
    Country ID

  - `data.document.company.city_id` (number)
    City ID

  - `data.document.company.timezone` (number)
    Timezone ID

  - `data.document.company.timezone_name` (string)
    Timezone name

  - `data.document.company.address` (string)
    location address

  - `data.document.company.coordinate_lat` (number)
    Latitude

  - `data.document.company.coordinate_lon` (number)
    Longitude

  - `data.document.company.logo` (string)
    Let, on which the location logo is located

  - `data.document.company.zip` (string)
    Postcode

  - `data.document.company.phones` (array)
    location phone

  - `data.document.company.site` (string)
    The site of the location

  - `data.document.company.phone` (string)
    Location phone number

  - `data.document.company.allow_delete_record` (boolean)
    Allow deleting records

  - `data.document.company.allow_change_record` (boolean)
    Allow changing records

  - `data.document.user` (object)
    User

  - `data.document.user.id` (number)
    User ID

  - `data.document.user.name` (string)
    Username

  - `data.document.user.phone` (string)
    User phone

  - `data.document.user.email` (string)
    User email

  - `data.document.user.is_approved` (boolean)
    Is user approved

  - `data.document.user.avatar` (string)
    User avatar URL

  - `data.client` (object | null)
    Client of a sale; null when there is none or the Business User may not see clients

  - `data.goods_transactions` (array)
    Product lines of the operation. `amount` is the quantity as sent, without a sign.

  - `data.goods_transactions.id` (integer)

  - `data.goods_transactions.document_id` (integer)

  - `data.goods_transactions.type_id` (integer)

  - `data.goods_transactions.type` (object)
    Transaction type

  - `data.goods_transactions.type.id` (number)
    Transaction type ID

  - `data.goods_transactions.type.title` (string)
    Transaction type name

  - `data.goods_transactions.company_id` (number)
    location ID

  - `data.goods_transactions.good_id` (number)
    Product ID

  - `data.goods_transactions.amount` (number)
    Quantity

  - `data.goods_transactions.cost_per_unit` (number)
    Unit price

  - `data.goods_transactions.cost` (number)
    Price

  - `data.goods_transactions.discount` (number)
    Discount

  - `data.goods_transactions.unit_id` (number)
    Unit ID

  - `data.goods_transactions.storage_id` (number)
    Inventory ID

  - `data.goods_transactions.supplier_id` (number)
    Vendor ID

  - `data.goods_transactions.client_id` (number)
    Client ID

  - `data.goods_transactions.master_id` (number)
    team member ID

  - `data.goods_transactions.create_date` (string)
    Line date in the Location timezone as `YYYY-MM-DD HH:MM:SS`

  - `data.goods_transactions.last_change_date` (string)
    Last modified date

  - `data.goods_transactions.comment` (string)
    A comment

  - `data.goods_transactions.deleted` (boolean)
    Delete transaction flag

  - `data.goods_transactions.good_special_number` (string)
    Special number (e.g., gift card code)

  - `data.goods_transactions.service_amount` (number)
    Service quantity

  - `data.goods_transactions.sale_amount` (number)
    Sale quantity

  - `data.goods_transactions.service_unit_id` (number)
    Service unit ID

  - `data.goods_transactions.sale_unit_id` (number)
    Sale unit ID

  - `data.goods_transactions.operation_unit_type` (number)
    Operation unit type

  - `data.goods_transactions.good` (object)
    Product

  - `data.goods_transactions.good.id` (number)
    Product ID

  - `data.goods_transactions.good.title` (string)
    Product Name

  - `data.goods_transactions.good.unit` (string)
    unit of measurement

  - `data.goods_transactions.good.value` (string)
    Product Name

  - `data.goods_transactions.good.label` (string)
    Product Name

  - `data.goods_transactions.good.article` (string)
    vendor code

  - `data.goods_transactions.good.category` (string)
    Product category name

  - `data.goods_transactions.good.category_id` (number)
    Product category ID

  - `data.goods_transactions.good.salon_id` (number)
    location ID

  - `data.goods_transactions.good.good_id` (number)
    Product ID

  - `data.goods_transactions.good.cost` (number)
    Price

  - `data.goods_transactions.good.unit_id` (number)
    Unit ID

  - `data.goods_transactions.good.unit_short_title` (string)
    Abbreviated name of the unit of measurement

  - `data.goods_transactions.good.service_unit_id` (number)
    Unit ID for the service

  - `data.goods_transactions.good.service_unit_short_title` (string)
    Abbreviated name of the unit of measure for the service

  - `data.goods_transactions.good.actual_cost` (number)
    Cost price

  - `data.goods_transactions.good.unit_actual_cost` (number)
    unit cost

  - `data.goods_transactions.good.unit_actual_cost_format` (string)
    Unit cost format

  - `data.goods_transactions.good.unit_equals` (number)
    Unit value

  - `data.goods_transactions.good.barcode` (string)
    Barcode

  - `data.goods_transactions.good.loyalty_abonement_type_id` (number)
    Membership ID (if the product is a membership)

  - `data.goods_transactions.good.loyalty_certificate_type_id` (number)
    Gift card identifier (if the product is a gift card)

  - `data.goods_transactions.good.loyalty_allow_empty_code` (number)
    Is it allowed to sell without a code

  - `data.goods_transactions.good.actual_amounts` (array)
    Quantity of products

  - `data.goods_transactions.good.last_change_date` (string)
    Date of last product change

  - `data.goods_transactions.good.comment` (string)
    Product comment

  - `data.goods_transactions.good.loyalty_certificate_type` (object | null)
    Gift card type details (if product is gift card)

  - `data.goods_transactions.good.loyalty_serial_number_limited` (number)
    Serial number limit flag

  - `data.goods_transactions.good.is_goods_mark_enabled` (boolean)
    Whether products marking is enabled

  - `data.goods_transactions.good.critical_amount` (number)
    Critical stock amount threshold

  - `data.goods_transactions.good.desired_amount` (number)
    Desired stock amount

  - `data.goods_transactions.good.is_chain` (boolean)
    Whether product belongs to chain

  - `data.goods_transactions.sale_unit` (any)
    Sales unit (can be object or null)

  - `data.goods_transactions.sale_unit.id` (number)

  - `data.goods_transactions.sale_unit.company_id` (number)
    Location ID. `company_id` is the literal legacy response field.

  - `data.goods_transactions.sale_unit.title` (string)

  - `data.goods_transactions.sale_unit.short_title` (string)

  - `data.goods_transactions.service_unit` (any)
    Sales unit for service (can be object or null)

  - `data.goods_transactions.service_unit.id` (number)

  - `data.goods_transactions.service_unit.company_id` (number)
    Location ID. `company_id` is the literal legacy response field.

  - `data.goods_transactions.service_unit.title` (string)

  - `data.goods_transactions.service_unit.short_title` (string)

  - `data.goods_transactions.goods_marks` (array)
    Product marking codes

  - `data.goods_transactions.storage` (object)
    Inventory

  - `data.goods_transactions.storage.id` (number)
    Inventory ID

  - `data.goods_transactions.storage.title` (string)
    Inventory name

  - `data.goods_transactions.supplier` (array)
    The supplier

  - `data.goods_transactions.client` (any)
    Customer (can be array or object)

  - `data.goods_transactions.client.id` (number)

  - `data.goods_transactions.client.name` (string)

  - `data.goods_transactions.client.phone` (string)

  - `data.goods_transactions.client.email` (string)

  - `data.goods_transactions.master` (any)
    Team Member (can be array or object)

  - `data.goods_transactions.master.id` (number)
    team member ID

  - `data.goods_transactions.master.name` (string)
    Team Member name

  - `data.goods_transactions.unit` (object)
    unit of measurement

  - `data.goods_transactions.unit.id` (number)
    Unit ID

  - `data.goods_transactions.unit.company_id` (number)
    Location ID

  - `data.goods_transactions.unit.title` (string)
    Unit name

  - `data.goods_transactions.unit.short_title` (string)
    Abbreviated name of the unit of measurement

  - `data.payment_transactions` (array | null)
    Payment transactions; null when the Business User has no access to them

  - `data.kkm_transactions` (array | null)
    Fiscal receipt transactions; null when the Business User may not print receipts

  - `data.abonements` (array)
    Memberships sold by the operation

  - `meta` (array)
    Metadata (empty array)

## Response 400:

  - `400` (unknown)
    Bad Request: no Team Member, or a date more than five minutes ahead of the current Location time

## Response 400 fields (application/json):

  - `success` (boolean)
    Response status.
    Example: false

  - `data` (object | null)
    Response data.
    Example: null

  - `meta` (object)
    Additional response data.

  - `meta.message` (string)
    Error message.
    Example: An error has occurred.

  - `meta.errors` (array)
    Set of a validation error messages.

## Response 401:

  - `401` (unknown)
    Unauthorized

## Response 401 fields (application/json):

  - `success` (boolean)
    Response status.
    Example: false

  - `data` (object | null)
    Response data.
    Example: null

  - `meta` (object)
    Additional response data.

  - `meta.message` (string)
    Error message.
    Example: Authentication needed.

## Response 403:

  - `403` (unknown)
    Forbidden

## Response 403 fields (application/json):

  - `success` (boolean)
    Response status.
    Example: false

  - `data` (object | null)
    Response data.
    Example: null

  - `meta` (object)
    Additional response data.

  - `meta.message` (string)
    Error message.
    Example: Access denied.

## Response 404:

  - `404` (unknown)
    Not Found: no such Team Member

## Response 404 fields (application/json):

  - `success` (boolean)
    Response status.
    Example: false

  - `data` (object | null)
    Response data.
    Example: null

  - `meta` (object | array)
    Additional response data (empty object or empty array)
    Example: {}

## Response 422:

  - `422` (unknown)
    Unprocessable Entity: an unsupported type, a line without `good_id` or `amount`, or a product of another Location

## Response 422 fields (application/json):

  - `success` (boolean)
    Response status.
    Example: false

  - `data` (object | null)
    Response data.
    Example: null

  - `meta` (object)
    Additional response data.

  - `meta.message` (string)
    Error message.
    Example: An error has occurred.

  - `meta.errors` (array)
    Set of a validation error messages.

