1

How I can update the inventory (stock_level) using (business manager API).

I use the business manager API to retrieve products. I am able to retrieve the products but I am not sure how I can set its stock (stock_level).

I have a special requirement where product quantity cannot exceed 1, so for that I need to set it in an inventory so that I can test it.

I have tried to see if I can set inventory level using product but that doesn't seem possible.

When I try to get inventory following is the error

{
    "_v": "18.8",
    "fault": {
        "arguments": {
            "method": "GET",
            "path": "/data/v18_8/inventory_lists/*"
        },
        "type": "ClientAccessForbiddenException",
        "message": "Access to resource 'GET /data/v18_8/inventory_lists/*' is not allowed for the current client."
    }
}
Jesse
  • 3,522
  • 6
  • 25
  • 40
  • What exactly are you trying? Can you share some a verifiable code sample that you're using? See [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Jesse Dec 04 '18 at 15:06

2 Answers2

0

There is actually a DATA API endpoint that can be used to update inventory. It is called the ProductInventoryRecords resource.

You can update a product inventory record with a PATCH eg:

PATCH /inventory_lists/{inventory_list_id}/product_inventory_records/{product_id}

With a ProductInventoryRecordAllocation payload as such:

{
    "_resource_state" : "847f9c3c5867f641470b3046aeec31f07757991b792d722e10079926f7a289fb",
    "allocation": {
        "amount": 2000,
        "reset_date": "2016-03-31T14:05:40.872Z"
    }
}

See more about this document type here.

Please note that the best practice is to pass the _resource_state key to ensure that the record is properly updated. OCAPI checks to see if this value is the same as the current state of the record if that attribute provided.

So systems should first check the record to get the _resource_state by performing a GET on the same resource.

Edit Note that you'll need an authorization token that grants you access to the API in order to make this kind of call.

sholsinger
  • 3,028
  • 2
  • 23
  • 40
-1

your question is not crystal clear but I will try to answer. Commerce Cloud has three distinct (OCAPI) APIs:

  • Shop API (provides similar access as a customer on the site)
  • Data API (provides similar access as a merchant using business manager)
  • Meta API (describes the API from a functional perspective)

To get availability of a product in the inventory use below call: {{shop_url}}/products/701644676568M/availability and look at ATS in the response.

To set the stocklevel go into to business manager or use business manager import utility. There is no out-of-the-box API to update the stocklevel.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Jesper
  • 304
  • 6
  • 10