This is a beta release of documentation for Magento 2.4, published for previewing soon-to-be-released functionality. Content in this version is subject to change. Links to the v2.4 code base may not properly resolve until the code is officially released.

Manage source items

If Magento is configured to manage inventory, when you upgrade to version 2.3, Magento assigns all existing products to the default source. Currently, Magento also assigns newly-created products to the default source. Single Source merchants do not need to manage source items, but Multi Source merchants may need to move products from the default source to a custom source, or move products from one custom source to another.

Service names:

1
2
3
inventoryApiSourceItemsDeleteV1
inventoryApiSourceItemsSaveV1
inventoryApiSourceItemRepositoryV1

REST endpoints:

1
2
3
POST V1/inventory/source-items-delete
POST V1/inventory/source-items
GET V1/inventory/source-items

sourceItems parameters:

Name Description Type Requirements
sku The SKU of an existing product String Required to assign or unassign a source
source_code The source to assign or unassign String Required to assign or unassign a source
quantity The total amount of inventory available for this SKU and source Float Optional
status Indicates whether the product is out of stock (0) or in stock (1) Integer Optional

Unassign products from a source

Use the POST V1/inventory/source-items-delete endpoint to unassign one or more products from the specified source. The sku and source_code attributes are required for each product.

Unassigning a source clears all quantity data. For this example, this is OK, because the default source did not contain any quantity data. Reassigning a source that contains real quantity data can potentially cause havoc with pending orders with reservations and affect the salable quantity counts. See the merchant documentation for more details.

Sample usage:

POST <host>/rest/<store_code>/V1/inventory/source-items-delete

Payload:

1
2
3
4
5
6
7
8
9
10
{
    "sourceItems": [{
        "sku": "new_product1",
        "source_code": "default"
    },
    {
        "sku": "new_product2",
        "source_code": "default"
    }]
}

Response:

Magento returns an empty array.

[]

Assign products to a source

POST V1/inventory/source-items is a powerful endpoint that allows you to define which sources carry each product as well as how many units are available at each source. You can use the endpoint to set up the initial quantities for each SKU at each source or add quantities as you receive shipments to replenish your supply.

The following example assigns 1000 units of product new_product1 to the central source and 2000 units to the east source. It also assigns 500 units of product new_product2 to the central source and 250 units to the east source.

Sample usage:

POST <host>/rest/<store_code>/V1/inventory/source-items

Payload:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
  "sourceItems": [{
    "sku": "new_product1",
    "source_code": "central",
    "quantity": 1000,
    "status": 1
  },
  {
    "sku": "new_product1",
    "source_code": "east",
    "quantity": 2000,
    "status": 1
  },
  {
    "sku": "new_product2",
    "source_code": "central",
    "quantity": 500,
    "status": 1
  },
  {
    "sku": "new_product2",
    "source_code": "east",
    "quantity": 250,
    "status": 1
  }]
}

Response:

Magento returns an empty array.

[]

Search for source items

The following call returns all source items for sku = new_product2.

See Search using REST APIs for information about constructing a search query.

Sample Usage:

GET <host>/rest/<store_code>/V1/inventory/source-items?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=new_product2&searchCriteria[filter_groups][0][filters][0][condition_type]=eq

Payload:

None

Response:

Show code sample
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{
    "items": [
        {
            "sku": "new_product2",
            "source_code": "central",
            "quantity": 500,
            "status": 1
        },
        {
            "sku": "new_product2",
            "source_code": "east",
            "quantity": 250,
            "status": 1
        }
    ],
    "search_criteria": {
        "filter_groups": [
            {
                "filters": [
                    {
                        "field": "sku",
                        "value": "new_product2",
                        "condition_type": "eq"
                    }
                ]
            }
        ]
    },
    "total_count": 2
}