3
votes

I am working with Shopify app for product details update by PHP in Shopify so anyone can please help me which API used for products details update in Shopify.

These following are details which I needs to update:

1) Products Price

2) Stock Availability

3) Products SKU

4) Products Variants

I found the method from https://help.shopify.com/api/reference/product#index which is below

Update a product, reordering the product variants

PUT /admin/products/#{id}.json

{
  "product": {
    "id": 632910392,
    "variants": [
      {
        "id": 457924702
      },
      {
        "id": 39072856
      },
      {
        "id": 49148385
      },
      {
        "id": 808950810
      }
    ]
  }
}

But how to use above code in my following function:

public function post_one($arrData){
        return $this->call('POST', '/admin/products.json', $arrData);
}
2

2 Answers

3
votes

Whenever you are updating a product/variant/anything in Shopify, you are required to do a PUT call rather than a POST call. POST is used to create something afresh.

Replace your function with the following. Here, the URL is in PUT /admin/products/#{id}.json format. Also note that, final URL must be like the following - https://{shopify-store}.myshopify.com/admin/....

public function put_one($arrData){
   return $this->call('PUT', '/admin/products/632910392.json', $arrData);
}
2
votes

If you are only modifying a single variant at a time, I highly recommend using the ProductVariant endpoint:

https://help.shopify.com/api/reference/product_variant#update

If you use the Product endpoint to update a single variant, you could unintentionally destroy the rest of the variants if you aren't careful.