Skip to main content
Bumped by Community user
Tweeted twitter.com/StackMagento/status/1063628182010630144
added 1 character in body
Source Link
KolonUK
  • 397
  • 1
  • 3
  • 10

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

{ 
  "stockItem""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?

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

{ 
  "stockItem": {
    "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?

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?

Source Link
KolonUK
  • 397
  • 1
  • 3
  • 10

API Stock update

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

{ 
  "stockItem": {
    "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?