Possible API Bug - Checkout Update - variant_id is invalid

marcosbruno
New Member
1 0 1

I was working on an app to update "properties" within a checkout "line_item" (reference: https://shopify.dev/docs/admin-api/rest/reference/sales-channels/checkout) For this development I am using Ruby gem Shopify but I believe that the situation below is repeated for other languages as reported in other posts here on the forum, for example:

  1. https://community.shopify.com/c/Shopify-APIs-SDKs/call-api-Creating-a-checkout-response-variantid-is...
  2. https://community.shopify.com/c/Shopify-APIs-SDKs/How-to-fixed-the-variant-id-code-invalid-message-i...

Since Shopify doesn't offer a feature for us to do update "Checkout Line Items Properties" directly on the Admin Panel I'm trying to do it through the Shopify API. So I started testing a simple Checkout creation:

// Create without line_items (which is an item marked as required in the documentation) it work:

 

 

$ ShopifyAPI::Checkout.create({ "email": "my@email.com" } )
=> #<ShopifyAPI::Checkout:0x000055a6b8ec19b8 @attributes={"email"=>"my@email.com", "token"=>"...

 

 

// Create with line_items didn't work:

 

 

$ variant_id = ShopifyAPI::Variant.last.id
$ checkout = ShopifyAPI::Checkout.create({ "email": "my@email.com", "line_items": [{"variant_id": variant_id, "quantity": 1}] } )
$ checkout.errors
=> #<ActiveResource::Errors:0x000055a6b8d641d8 @Base=#<ShopifyAPI::Checkout:0x000055a6b8d64cf0 @attributes={"email"=>"my@email.com", "line_items"=>[#<ShopifyAPI::LineItem:0x000055a6b8d64458 [omitted] @errors=#<ActiveResource::Errors:0x000055a6b8d641d8 ...>>, @errors=[#<ActiveModel::Error attribute=line_items, type=["0", {"variant_id"=>[{"code"=>"invalid", "message"=>"is invalid", "options"=>{}}]}], options={}>]>

 

 

I tested several different paths and options (I could describe it but it would be too long) but nothing worked. Even the simplest updates do not work for checkout (but they are other cases and deserve to be reviewed separately).

So I decided to try it directly via Postman and (as documented in https://shopify.dev/docs/admin-api/rest/reference/sales-channels/checkout) I did a PUT request with:

 

 

{
   "checkout": {
       "token": "abcd1234",
       "line_items": [
           {
               "variant_id": 1234,
               "quantity": 1,
               "properties": {
                   "prop": foo,
               }
           }
       ]
   }
}

 

 

And I got de same "variant_id is invalid". So I decided to test variations in the parameters for this request. Until I was successful in this:

 

 

{
   "checkout": {
       "token": "abcd1234",
       "line_items": [
           {
               "variant_id": "1234", // notice variant_id in "quotes"
               "quantity": 1,
               "properties": {
                   "prop": foo,
               }
           }
       ]
   }
}

 

 

As also noted in other requests, when using the Shopify gem (or another resource) the "variant_id" is converted to a number and the above error is returned. But when we perform the search manually and enter the "variant_id" as a string when updating a Checkout, the request is successful.

There may have been some misunderstanding on my part about the documentation, but I leave these observations eventually to anyone who experiences the same difficulty.

Kind regards.

syf_
Shopify Staff
Shopify Staff
89 20 15

Hi @marcosbruno,

I took a look into this but I was unable to reproduce the behaviour you described in your post. Are you still experiencing this? If you are, could you please provide me with replication steps so I could investigate further.

Thanks,
Seth.

syf_ | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes