"Write requests to inventory_quantity and inventory_quantity_adjustment are no longer supported.

Highlighted
Shopify Partner
2 0 0

This is quite crazy. I have the following code finding a product, attaching an image, and then updating the tags.

 

The code is in rails, using the shopify_api gem v9.0.1. In my configuration, I am interacting with the 2020-01 API version

 

begin
     logger.debug "PhotosController begin"
     p = ShopifyAPI::Product.find( inventory_report_row.product_id )
     logger.debug "Product found"
     f = File.read( params[:photos].path )
     logger.debug "File read"
     i = ShopifyAPI::Image.new(:product_id => p.id)
     logger.debug "Image ActiveResource object created"
     if (p.images.length + 1) == 4
          # Set to Store Light
          logger.debug "Image length now shows 4"
          p.tags = p.tags + ", Store_light_photos"
          logger.debug "Tags added"
          p.save
          logger.debug "Product saved"
       end
       i.attach_image(f) # <-- attach_image is a method, not an attribute
       logger.debug "Image attached"
       image_save_result = i.save
       logger.debug "image_save_result"
       logger.debug image_save_result
rescue => e
       logger.debug e.message
       logger.debug e.backtrace[0..9]
end

It has worked for years. However, when I am running, apparently the p.save line is causing an inventory_quantity error, despite the fact I am doing absolutely nothing with that now deprecated property. See the logged result of running that code:

PhotosController begin

Product found

File read

Image ActiveResource object created

Image length now shows 4

Tags added

Failed.Response code = 400.Response message = Bad Request (Write requests to inventory_quantity and inventory_quantity_adjustment are no longer supported. Please use the Inventory Levels API.).

 

I understand how to solve that error by using the InventoryLevels api when I am trying to deal with inventory quantities, etc. But I have no idea why that error would throw here, or solve that error, as I am not doing anything with inventory quantity. Neither writing, nor trying to access that property.

 

Also strangely, this error is happening on our production server, but running the same code on my localhost computer, with the same v9.0.1 shopify_api gem generates no such error, and the code runs fine.

 

Any ideas?

 

0 Likes
Highlighted
Shopify Partner
16 0 7

I, too, am experiencing this when just adding images to products. This seems like a bug on Shopify's end.

 

It would be great if someone from Shopify could chime in.

0 Likes
Highlighted
New Member
1 0 0

I'm seeing exactly the same issue.  Same code I used last week using the Products API (via python sdk) is producing the same :

 

"Write requests to inventory_quantity and inventory_quantity_adjustment are no longer supported"

 

If I take the initial inventory value out of the payload the error goes away.

0 Likes
Highlighted
Shopify Partner
16 0 7

I just figured out how to solve this. I had to delete the following variables from variables before saving products or before saving variants:

 

inventory_quantity
inventory_quantity_adjustment
old_inventory_quantity

 

Example:

 

params.variants.forEach(variant => {
  delete variant.inventory_quantity;
  delete variant.inventory_quantity_adjustment;
  delete variant.old_inventory_quantity;
});

 

I am using the shopify-api-node Node package, so I went a step further and monkey patched the client:

 

const Shopify = require('shopify-api-node');

const patchClient = client => {
  const originalProductUpdate = client.product.update;

  client.product.update = function(id, params) {
    params = { ...params };

    if (params && params.variants) {
      params.variants.forEach(variant => {
        delete variant.inventory_quantity;
        delete variant.inventory_quantity_adjustment;
        delete variant.old_inventory_quantity;
      });
    }

    return originalProductUpdate.call(client.product, id, params);
  };

  return client;
};

let client = new Shopify({
  shopName,
  accessToken,
  autoLimit: { calls: 1, interval: 1000, bucketSize: 13 },
  timeout: 2 * 60 * 1000,
  apiVersion: '2020-01'
});

client = patchClient(client);

 

It would be wonderful if Shopify's API response mentioned old_inventory_quantity. I had first tried deleting inventory_quantity and inventory_quantity_adjustment, but this was not enough; I also had to delete old_inventory_quantity.

 

Shopify, please update your API error response to include this detail. We had lots of angry customers resulting from this.

0 Likes