14

Using Magento 2.2.2, I was trying to add stock updates to a pre-existing setup using the official defined endpoint:

rest/V1/products/testsku/stockItems/1

with

{ 
  "stock_item": {
    "qty": 1234,
    "is_in_stock": true
  }
}

which wouldn't work. Searching around, I found an example here which essentially strips the product create/update JSON right back to the bare minimum and just include the stock data:

rest/V1/products/testsku

.

{
  "product": {
    "sku": "testsku",
    "extensionattributes": {
      "stockitem": {
        "qty": 1234,
        "isinstock": true,
      }
    }
  },
 "saveOptions": true
}

I changed my stock update process to call this instead, and it works.

However, I noticed afterwards that the extensionattributes (and it's sub fields) is missing the underscore, according to the official swagger API documentation. My product create call already includes the underscore fields when creating the item to set an initial stock quantity, yet don't seem to be working.

What's the difference - underscore or no underscore? Which is correct? Is this a bug or an undocumented change, or are both field names valid?

2 Answers 2

5

Using this documentation : Magento Commerce for B2B v2.2, I was able successfully create API calls for the stockItem.

This is a PUT operation, make sure that you get the correct item_id for that product.

/V1/products/{productSku}/stockItems/{itemId}

item_id from GET Product API:

"stock_item": { "item_id": 4721, "qty": 1234, "is_in_stock": true }

Also, regarding the underscores, I think it would be safer to follow what is in the documentation, but based on my experience, both works:

enter image description here

PS. I use Postman for testing the APIs.

0

the answer from V Salvador does work, thanks.

However, it is worth noting if the SKU is simple, then qty matches the value in the API data.

If the SKU is a configurable, or composite in general, the qty will not match the API data.

The flag is_in_stock will change for all types of products.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.