Hey everyone - very quick question. How do you update a product's price via the API? Just including a "price" key/value in the PUT/POST payload isn't doing the trick. Do I have to create a product variant for this, even if my product has no variants?
Thanks for your help!
Solved! Go to the solution
Hi @anonymous1 ,
Use your product ID for variant ID see if that works. Also wouldn't hurt to show us what you're payload and any errors.
Regards,
Sam
Thanks! I guess that's my question - do you have to update a "variant" to update price? The docs are surprisingly silent about what I would think would be a top-level operation for any Shopify dev - updating price via API.
Here's what my payload looks like to the /products endpoint:
product_payload = { 'product': { 'title': self.title, 'body_html': self.description, 'published': self.published, 'price': json.dumps(self.price, use_decimal=True) } }
Everything but price gets updated/set correctly.
Thanks for your time!
This is an accepted solution.
I want to respond to my own thread here with the solution. A thing that is not 100% clear about Shopify products is that they DO NOT have a price associated with them. Only the product VARIANTS have prices. Even if you have a product with no variants, Shopify has secretly created a single variant for your product and this is the object that contains your price. So if you wanted to update your product's price, you can't make a call to /products/{product.id}.json you have to call /variants/{variant.id}.json with price as part of the payload. A bit confusing and not exactly spelled out, but makes sense!
remember running into this and yes the docs didn’t make it clear what ID to use when a product has no variants. My vote towards enhancing the document for Orders API.
var data = JSON.stringify({
"product": {
"title": "Test",
"body_html": "Test",
"vendor": "Test",
"product_type": "Test",
"variants": [
{
"title": "Test1",
"price": "500"
}
]
}
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("PUT", "https://myshopify.com/admin/products/5192344207495.json");
xhr.setRequestHeader("x-shopify-access-token", "privatekey");
xhr.setRequestHeader("host", "lonely-walls-inc.myshopify.com");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.setRequestHeader("postman-token", "17fb6a1b-1763-3646-21a1-409e1c23b22c");
xhr.send(data);
User | Count |
---|---|
25 | |
8 | |
7 | |
5 | |
4 |