Reputation: 17
I am trying to figure out the best way to update our prices via the API
Normal SKUs are fine, but the price of items with options seems a little less straightforward.
Using the GET v2/products?sku=XXXX there is only the base price of the item, not the price of the item with the option(s) selected
We also need the SKU of the item when the option(s) is(are) selected as my updated price list has SKU and Price.
What is the best method of gathering this information, and then updating the prices?
Upvotes: 0
Views: 819
Reputation: 684
The V3 API provides a much better interface for this.
If all of your product's options are related to SKUs, you can GET all of the details of the product with its variants via
/v3/catalog/products?include=variants
This will show you option information along with all pricing - the calculated_price
property will give you an idea of what the real price will be when you click on the option values for that SKU on the storefront - so it will take into account (for example) Product Rules and other things that might be going on in the background.
Editing SKUs (such as their price) can also be done via the endpoint.
Example:
PUT /v3/catalog/products/6606?include=variants (where 6606 is the Product ID)
{
"variants": [
{
"id": 25858,
"product_id": 6606,
"price": 10
},
{
"id": 25859,
"product_id": 6606,
"price": 11
},
{
"id": 25860,
"product_id": 6606,
"price": 13
}
]
}
This would update the prices of these 3 variants on the product (you'd get their IDs from the GET response).
If the product is "simple", meaning it has no child SKUs, you'll also see the product represented as a variant with sku_id=null. So you can actually use this endpoint to update the prices of simple products as well.
Upvotes: 4