Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"inventory_quantity"=>"expected String to be a Integer"} on variant.save #969

Closed
jacksonSingleton opened this issue May 26, 2022 · 21 comments
Labels

Comments

@jacksonSingleton
Copy link

jacksonSingleton commented May 26, 2022

Issue summary

Write a short description of the issue here ↓
When calling save on a product variant, it returns the error 'request': {"inventory_quantity"=>"expected String to be a Integer"} (ShopifyAPI::Errors::HttpResponseError) despite not modifying inventory quantity at all.

Here's my code block that the error is tracing to

def modify_inventory_management(item)
  puts item.inspect
  item.fulfillment_service = 'manual'
  item.inventory_management = 'shopify'
  item.save
end

Expected behavior

What do you think should happen?
So my code was previously working before upgrading to v10.x from gem version 9.5.1. I would assume it would just write and give a 200 status

Actual behavior

What actually happens?

`'request': {"inventory_quantity"=>"expected String to be a Integer"} (ShopifyAPI::Errors::HttpResponseError)`

Steps to reproduce the problem

  1. Just calling product.variant[0].save is producing the problem even without modifying any fields

Logs

If applicable, enable the logs as described in the README, and paste the relevant portion here.

So here's the output of product.variant.first.inspect where on option1 the inventory_quantity field is correctly set to 0 rather than a string as described in an error

#42522703003872, :product_id=>7583295275232, :title=>"Default Title", :price=>"431.96", :sku=>"", :position=>1, :inventory_policy=>"deny", :compare_at_price=>"479.95", :fulfillment_service=>"manual", :inventory_management=>"shopify", :option1=>"Default Title", :option2=>nil, :option3=>nil, :created_at=>"2022-03-09T15:40:35-06:00", :updated_at=>"2022-05-24T12:20:53-05:00", :taxable=>false, :barcode=>"", :grams=>0, :image_id=>nil, :weight=>0.0, :weight_unit=>"lb", :inventory_item_id=>44617021161696, :inventory_quantity=>0, :old_inventory_quantity=>0, :requires_shipping=>true, :admin_graphql_api_id=>"gid://shopify/ProductVariant/42522703003872"}, @custom_prefix=nil, @forced_nils={"id"=>false, "product_id"=>false, "title"=>false, "price"=>false, "sku"=>false, "position"=>false, "inventory_policy"=>false, "compare_at_price"=>false, "fulfillment_service"=>false, "inventory_management"=>false, "option1"=>false, "option2"=>true, "option3"=>true, "created_at"=>false, "updated_at"=>false, "taxable"=>false, "barcode"=>false, "grams"=>false, "image_id"=>true, "weight"=>false, "weight_unit"=>false, "inventory_item_id"=>false, "inventory_quantity"=>false, "old_inventory_quantity"=>false, "requires_shipping"=>false, "admin_graphql_api_id"=>false}, @aliased_properties={}, @session=#, @expanded_scopes=#>, @associated_user_scope=nil, @expires=nil, @associated_user=nil, @is_online=true, @shopify_session_id=nil>, @client=#"Shopify API Library v10.1.0 | Ruby 3.0.3", :Accept=>"application/json", "X-Shopify-Access-Token"=>"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"}>, @errors=#, @barcode="", @compare_at_price="479.95", @created_at="2022-03-09T15:40:35-06:00", @fulfillment_service="manual", @grams=0, @id=42522703003872, @image_id=nil, @inventory_item_id=44617021161696, @inventory_management="shopify", @inventory_policy="deny", @inventory_quantity=0, @inventory_quantity_adjustment=nil, @old_inventory_quantity=0, @option=nil, @position=1, @presentment_prices=nil, @price="431.96", @product_id=7583295275232, @requires_shipping=true, @sku="", @tax_code=nil, @Taxable=false, @title="Default Title", @updated_at="2022-05-24T12:20:53-05:00", @weight=0.0, @weight_unit="lb", @Option1="Default Title", @option2=nil, @option3=nil, @admin_graphql_api_id="gid://shopify/ProductVariant/42522703003872">

Specifications

  • shopify_api version: v10.1.0
  • Shopify API version used: Attempted with both 2022-01 and 2022-04
@breiko83
Copy link

breiko83 commented Jun 10, 2022

Hello! Having the same issue here. Did you have any luck solving this?

shopify_variant = ShopifyAPI::Variant.find(id: variant_shopify_id, session: ShopifyAPI::Context.active_session)
shopify_variant.save

ShopifyAPI::Errors::HttpResponseError ({"inventory_quantity"=>"expected Hash to be a Integer"})
If you report this error, please include this id: 00f34b32-2e11-4529-b95b-5ae77e4330a7.

Also tried to manually set inventory quantity to integer but same error

shopify_variant = ShopifyAPI::Variant.find(id: variant_shopify_id, session: ShopifyAPI::Context.active_session)
shopify_variant.inventory_quantity = 0
shopify_variant.save

ShopifyAPI::Errors::HttpResponseError ({"inventory_quantity"=>"expected Hash to be a Integer"})
If you report this error, please include this id: d5a0fca5-ccbc-4b1c-904b-51cbdc224c58.

@jcroucher
Copy link

Did you manage to solve this? I am also having the same issue.

@schappim
Copy link

schappim commented Jul 29, 2022

One thought: What happens if you change the API version?

@caseyprovost
Copy link

caseyprovost commented Aug 18, 2022

Same here on API version "2022-07"

-- EDIT--

Updating to 2022-07 results in the exact same error

@caseyprovost
Copy link

For anyone still stuck (like I am)...there is a workaround. Simply use the GraphQL Admin client instead of the REST one. I've found it to work when the REST API client is broken for each and every case. Including this one, but also deleting collections and variants. Not a great fix, but it works.

@tiredenzo
Copy link

Same issue here. Would be nice to have a fix, thanks in advance

@github-actions
Copy link

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Nov 19, 2022
@schappim
Copy link

Bump to keep this open. Has Shopify said they’re depreciating the REST client? It’d be nice to get a clear “if you’re building new apps, don’t use this API”.

@github-actions github-actions bot removed the Stale label Nov 20, 2022
@benichu
Copy link

benichu commented Dec 13, 2022

having the same kind of errors as one described in the thread:

ShopifyAPI::Errors::HttpResponseError ({"inventory_quantity"=>"expected Hash to be a Integer"})

Tried versions 10.1.1 and 12.3.0 of this library (REST mode) with the same result.

@schappim
Copy link

@benichu we've given up on the Shopify Gem, and just built our own wrapped for the REST API.

@jacksonSingleton
Copy link
Author

Sorry for the late reply for anyone searching. I had to solve this by just using REST calls with anything new that I write. Kinda sucks because I had a ton of work set up using the gem. Gotta love the Shopify devex.

@benichu
Copy link

benichu commented Dec 14, 2022

You both confirmed what I thought.
I really need to decide what to do, I tried to look into the gem itself, but I can't be bothered with that Sorbet misdirection sprinkled everywhere... Also, I don't care about the GraphQL version, I have other things to worry about than adding a new concept to communicate with HTTP remote services.
I guess I'll write a quick REST wrapper like you both did to give me time to reconsider my next move with the Shopify integration

We can't have good and lasting tech anymore, it feels like big tech companies like Shopify and others are on a treadmill to change services and libraries for the sake of it.

When I think that I only started that rabbit hole of a waste of time because of an Unauthorized ([API] Invalid API key or access token (unrecognized login or wrong password)) error out of nowhere 🤷

All I want is to be able to integrate my application with Shopify and forget it. I don't care if it means locking a client library and API backend versions and foregoing some "new amazing" features. I honestly don't want to have to read every developer announcement and deprecation notice required by the "new" growth strategy...
I just want to keep on synchronizing 2 product catalogs for god's sake 😢

@schappim
Copy link

schappim commented Dec 14, 2022

All I want is to be able to integrate my application with Shopify and forget it.

Yeah, tell me about it. In the end my business partner and I ended just writing our own ecommerce platform.

The decision to do so was heavily influenced by the gem and the app store review!

@matthewford
Copy link

Anyone managed to resolve this?

@acflint
Copy link

acflint commented Jan 14, 2023

Also having this issue when trying to update a variant's fulfillment service. On save I get {"inventory_quantity"=>"expected String to be a Integer"}.

Like others, I've also had to revert to using the REST client directly: rest_client.put(path: "/variants/#{variant.id}.json", body: {variant: {fulfillment_service: @fulfillment_service.handle}})

No reply from Shopify on this, eh? That's too bad.

@benichu
Copy link

benichu commented Jan 14, 2023

Yep, ended up removing the gem and writing a small REST client with zero useless abstractions to worry about.
It's been in production for a week, feeling better now. As long as they keep their REST API backward compatible 🤞

@benichu
Copy link

benichu commented Jan 14, 2023

Bonus now, is that my client properly uses the Retry-After header so I don't have to worry about batch requests exceeding the 40 per-minute server limit.

@github-actions
Copy link

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Mar 16, 2023
@github-actions
Copy link

We are closing this issue because it has been inactive for a few months.
This probably means that it is not reproducible or it has been fixed in a newer version.
If it’s an enhancement and hasn’t been taken on since it was submitted, then it seems other issues have taken priority.

If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines

Thank you!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 31, 2023
@artyrcheek
Copy link

Deffo hasn't been fixed

@remy727
Copy link
Contributor

remy727 commented Nov 23, 2023

For anyone who has this issue, I go with this solution finally.

test_session = ShopifyAPI::Auth::Session.new(
  shop: your_shop,
  access_token: your_access_token,
)

client = ShopifyAPI::Clients::Rest::Admin.new(session: test_session)
body = {
  variant: {
    cost: 4.50
  }
}
response = client.put(path: "variants/#{variant_id}.json", body: body)
puts response.body

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests