Shopify Api for products details updating using PHP

Active3 hr before
Viewed126 times

4 Answers


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.,, Meta Stack Overflow ,Thanks for contributing an answer to Stack Overflow!

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}

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

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.,I can develop a shopify app, I can use the shopify_api (in rails), I can do a lot of thing, but I could find the way to use the api from frontend... I'd like to develop an ajax filter for frontend, ...,I'm trying to retrieve products from my Shopify store with this code, a near copy/paste of the examples page for the Javascript Buy SDK: $(function() { var shopClient = ShopifyBuy.buildClient({ ...,Update a product, reordering the product variants

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

   "product": {
      "id": 632910392,
      "variants": [{
            "id": 457924702
            "id": 39072856
            "id": 49148385
            "id": 808950810
load more v

Now, what we want to do is when we select a product. A bootstrap modal should appear and allow us to select new collections for our product.,Once you’re done copying the code, we should then be able to use it instead of the parse_str() function.,The scripts above should allow us to edit and save a new title and description for any of the products that we select below.,Now if we save all of our scripts and run the app, we should then be able to update the collections without any problem. Awesome!

And for our ajax.php, we should have the following code:

< ? php

$id = $_POST['id'];
$shop_url = $_POST['url'];

$sql = "SELECT * FROM shops WHERE shop_url='".$shop_url.
"' LIMIT 1";
$check = mysqli_query($conn, $sql);

if (mysqli_num_rows($check) > 0) {
   $shop_row = mysqli_fetch_assoc($check);

   $token = $shop_row['access_token'];

   if ($_POST['type'] == 'GET') {
      $products = shopify_call($token, $shop_url, "/admin/api/2020-07/products/".$id.
         ".json", array(), 'GET');
      $products = json_decode($products['response'], JSON_PRETTY_PRINT);

      $id = $products['product']['id'];
      $title = $products['product']['title'];
      $description = $products['product']['body_html'];
      $collections = array();

      $custom_collections = shopify_call($token, $shop_url, "/admin/api/2020-07/custom_collections.json", array("product_id" => $id), 'GET');
      $custom_collections = json_decode($custom_collections['response'], JSON_PRETTY_PRINT);

      foreach($custom_collections as $custom_collection) {
         foreach($custom_collection as $key => $value) {
            array_push($collections, array("id" => $value['id'], "name" => $value['title']));

      $smart_collections = shopify_call($token, $shop_url, "/admin/api/2020-07/smart_collections.json", array("product_id" => $id), 'GET');
      $smart_collections = json_decode($smart_collections['response'], JSON_PRETTY_PRINT);

      foreach($smart_collections as $smart_collection) {
         foreach($smart_collection as $key => $value) {
            array_push($collections, array("id" => $value['id'], "name" => $value['title']));

      echo json_encode(
            "id" => $id,
            "title" => $title,
            "description" => $description,
            "collections" => $collections

   } else if ($_POST['type'] == 'PUT') {
      $productData = array();
      $productData = proper_parse_str($_POST['product']);

      $array = array("product" => array("title" => $productData['productName'], "body_html" => $productData['productDescription']));

      $products = shopify_call($token, $shop_url, "/admin/api/2020-07/products/".$id.
         ".json", $array, 'PUT');

} ?
Code language: PHP(php)
load more v

This code uses your terminal/command prompt to execute the php script and requires the “write_products” scope in Shopify’s API.,I’m using the code below to update hundreds of product tags in Shopify, you might be able to find an app in Shopify but this way seems quicker for me.,Fill in the $config variable with your store details, make sure "write_products" scope has read/write access.,Using composer: composer require phpclassic/php-shopify

Run the PHP script from your terminal.

< ? php

// command line tool used to bulk update tags for products in shopify
// make sure api has access to "write_products" scope
// usage: php update.php


use PHPShopify\ ShopifySDK;

// config
$config = array(
   'ShopUrl' => '',
   'ApiKey' => '***YOUR-PRIVATE-API-KEY***',
   'Password' => '***YOUR-PRIVATE-API-PASSWORD***',

// setup $shopify
$shopify = PHPShopify\ ShopifySDK::config($config);

// download all the products
$productResource = $shopify - > Product();
$products = $productResource - > get(['limit' => 250]);
$nextPageProducts = $productResource - > getNextPageParams();
$nextPageProductsArray = [];

while ($nextPageProducts) {
   $nextPageProductsArray = $productResource - > get($productResource - > getNextPageParams());
   $products = array_merge($products, $nextPageProductsArray);
   $nextPageProducts = $productResource - > getNextPageParams();

// update tags for each product
foreach($products as $product) {
   if (count($product['variants']) > 0) {
      $tags = explode(",", $product['tags']);

      $tags = array_map(function($a) {
         return trim($a);
      }, $tags);

      // append tags
      $tags[] = 'Append This Tag';

      // delete duplicates
      $tags = array_unique($tags);
      $tags = array_filter($tags);

      // update
      try {
         $shopify - > Product($product['id']) - > put([
            'tags' => join(',', $tags)

         echo sprintf('UPDATE TAG: %d'.PHP_EOL, $product['id']);
      } catch (Exception $e) {
         echo sprintf('UPDATE TAG FAILED: %d'.PHP_EOL, $product['id']);

      // rest

echo PHP_EOL;
echo 'DONE';
echo PHP_EOL;

Other "products-undefined" queries related to "Shopify Api for products details updating using PHP"