2

I'm trying to update a particular product in Magento through PUT using python. I'm using OAuth1Service for authentication to Magento 2. GET products is actually giving me all the products in Magento where as PUT payload is not taking payload.

My payload is a JSON string

'''{
   "product": {
   "price": 1,
   "extension_attributes": {
   "stock_item": {"qty": 2}
   }
  }
}'''

My put request looks like this, the headers has the authentication token and the content type inside it.

payload = json.loads(product)
r = session.put(
'products/12345',
headers=headers,
data=json.dumps(payload),
)

Rather than taking the payload, it is giving me this error:

enter image description here

1

Magento is trying to load the product by SKU but you didn't send it in your Json. Even though you are passing the SKU on your URL, SKU is still a required field. , try with:

{
  "product": {
  "price": 1,
  "sku": 12345,
  "extension_attributes": {
  "stock_item": {"qty": 2}
  }
 }
}

Here in swagger is showing that SKU is required. Follow swagger for your next requests.

Swagger tutorial

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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