Ad

Shopify Api For Products Details Updating Using PHP

- 1 answer

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);
}
Ad

Answer

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);
}
Ad
source: stackoverflow.com
Ad