Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Product Set Mutation issues

Solved

Product Set Mutation issues

PriLopes
Shopify Partner
13 0 16

I'm trying to update my service to use new 2024-07 version and I came across several problems. For some of them I've found a workaround which I think are not so great and for some others I'm stuck. I'd appreciate some help with it.

 

1. The main motivator to update the version for my team was the new 2k limit for variants. But when I tried it it doesn't allow me to add more than 100. So how does that work exactly? Is it even available yet?

 

2. For our workflow, whenever we update the product we need to replace all the media. Is there a simpler way to do so rather than making a request to get the old one, then another one to delete them and then a third one to add the new media? 

 

3. Since `productSet` mutation doesn't allow us to set some variant attributes such as inventoryItem I'm calling productVariantsBulkUpdate after that to set the it. But then I face another issue, it says I can't with the error: 

 

Inventory quantities can only be provided during create. To update inventory for existing variants, use inventoryAdjustQuantities

 

Which sounds very confusing since it's not posible to add it in creation as creation is done now with productSet and it doesn't have the possibility to include that information. But then if I try to use inventoryAdjustQuantities I have one more error. What am I missing here?

{
    "code": "ITEM_NOT_STOCKED_AT_LOCATION",
    "field": [
        "input",
        "changes",
        "0",
        "locationId"
    ],
    "message": "The specified inventory item is not stocked at the location."
}

 

4. Is that really the way we should go with now? Doing that many api calls? I really hope that it is just something I'm missing here, otherwise, for a simple product creation it will require at least 5 requests to set all the necessary data and get it published. If that's the way than it implicates a worse performance and serious risks of reaching api rate limits way faster with so many calls for a single product.

 

Thanks in advance

 

Accepted Solution (1)
cbella
Shopify Staff
3 2 1

This is an accepted solution.

Hello @PriLopes,

 

The reason you are receiving the `LOCATION_NOT_FOUND` error for that location is because the location is a fulfillment_service location that has `permitsSkuSharing` set to false.

The error message is misleading and we should have a better error code to make that clear. I will see to it that we clear up our error messaging there.

 

If you can modify the fulfillment service to have `permitsSkuSharing` set to true, then calling inventoryBulkToggleActivation should succeed.

 

When a fulfillment service has `permitsSkuSharing` set to false, it means that the inventory can only be stocked at that fulfillment service location and no other locations.

 

I hope that helps!

Let me know!

View solution in original post

Replies 20 (20)

AsafGitai
Shopify Staff
109 16 45

Hi @PriLopes ,


1. you need to use a dev store and turn on the extended variants preview

AsafGitai_0-1722647156358.png


2. not sure i understand why you need to replicate the media when you are updating the product. FileCreate has duplicateresolutionmode that my be relevant. We are also considering adding fileCreatre capabilities to productSet in the near future.

3. I beleive you can use inventorySetQuantities with ignoreCompareQuantity

4, Keep in mind that productSet cost is higher than other calls.

hope this helps



PriLopes
Shopify Partner
13 0 16

Hi @AsafGitai , thanks for replying!

 

Sorry, I still have questions 😅

 

1. So, only new dev stores will be able to use the new variants? What about the non-dev stores? When they will be able to use the extended variants feature?

 

2. So, our app is a third part fulfillment service, so we need to use the `productSet` mutation to keep the products up to date in our platform and Shopify. When we save products in our side it means the products have been updated and that includes the media as well. Which means we need to replace all the previous media for that product. So it would be helpfull if we could use a mutation that would replace the media instead of just appending new images.

 

3. I've tried this and I get the same error

{
  code: "ITEM_NOT_STOCKED_AT_LOCATION",
  field: [
    "input",
    "quantities",
    "0",
    "locationId",
  ],
  message: "The specified inventory item is not stocked at the location.",
}

That was the mutation I've tried

mutation inventorySetQuantities($input: InventorySetQuantitiesInput!) {
  inventorySetQuantities(input: $input) {
    inventoryAdjustmentGroup {
      reason
      referenceDocumentUri
      changes {
        name
        delta
        quantityAfterChange
      }
    }
    userErrors {
      code
      field
      message
    }
  }
}

and the variables:

{
    "input": {
        "name": "available",
        "reason": "correction",
        "ignoreCompareQuantity": true,
        "quantities": [
            {
                "locationId": "gid://shopify/Location/{{my_app_location_id}}",
                "inventoryItemId": "gid://shopify/InventoryItem/{{my_variant_inventory_item_id}}",
                "quantity": 100
            }
        ]
    }
}

 

4. Okay, it makes sense but in our case it will be worth it as we need to handle 100+ variants. So, can you confirm if the flow I'm using here is correct?

  • productSet mutation to create or update the product
  • productOperation query to get the set operation and the product
  • productDeleteMedia to clean up old media (if it's an update)
  • productCreateMedia to aappend the new media
  • productVariantsBulkUpdate to set up inventory item for product variants
  • inventorySetQuantities to enable fulfillment inventory
  • publishablePublish to publish the product to the online store

Thanks again for your help
AsafGitai
Shopify Staff
109 16 45

1. ATM this is only available in dev preview

> 2. So it would be helpfull if we could use a mutation that would replace the media instead of just appending new images.
AFAIK calling productSet with MediaIds should leave the product with ONLY those ids ( meaning emove any ids not passed in) - let me know if that is not the case and we can look into it

AsafGitai_0-1722871820662.png


3. i'll inform the team, but for now you could also use https://shopify.dev/docs/api/admin-graphql/2024-07/mutations/inventoryBulkToggleActivation

4. productDeleteMedia seems unnecessary as mentioned above
 productCreateMedia for now, soon should be able to do in same call to productSet
productVariantsBulkUpdate or inventoryBulkToggleActivation


otherwise seem correct. we are considering adding publishablePublish to productSet for convenience as well. 

PriLopes
Shopify Partner
13 0 16

Okay, got it.. for media it's all good then.

 

Yes! It will be super helpful if you add both media create and publish at productSet 🙏

 

About inventoryBulkToggleActivation I think there might be a bug 🤔I've tried this:

mutation inventoryBulkToggleActivation {
  inventoryBulkToggleActivation(
    inventoryItemId: "gid://shopify/InventoryItem/{{my_variant_inventory_item_id}}",
    inventoryItemUpdates: [
        {
            activate: true,
            locationId: "gid://shopify/Location/{{my_location_id}}"
        }
    ]) {
    inventoryItem {
      id
    }
    inventoryLevels {
      id
      quantities(names: ["available"]) {
        name
        quantity
      }
      location {
        id
      }
    }
    userErrors {
      field
      message
      code
    }
  }
}

and got this error:

[
    {
        "field": [
            "inventoryItemUpdates",
            "0",
            "locationId"
        ],
        "message": "The quantity couldn't be updated because the location was not found.",
        "code": "LOCATION_NOT_FOUND"
    }
]

and I'm sure the location id is correct because I've coppied directly from Shopify Admin 

AsafGitai
Shopify Staff
109 16 45

Hard to say without more specific info

PriLopes
Shopify Partner
13 0 16

So, this is what I need:

 

I have an app for our fulfillment service. So when I create a product I need to associate it with our fulfillment so later the user can request fulfillment for an order. In this update I'm following these steps I've mentioned

  • productSet mutation to create or update the product
  • productOperation query to get the set operation and the product
  • productDeleteMedia to clean up old media (if it's an update)
  • productCreateMedia to aappend the new media
  • productVariantsBulkUpdate to set up inventory item for product variants
  • inventorySetQuantities to enable fulfillment inventory
  • publishablePublish to publish the product to the online store

But inventorySetQuantities fails with ITEM_NOT_STOCKED_AT_LOCATION and inventoryBulkToggleActivation fails with LOCATION_NOT_FOUND. With old api version it worked fine by setting the inventory item in variant input for productCreate or productUpdate. And if I try to do this now via UI it works as well, which indicates there is something weird going on with new mutations.

 

It would actually solve the problems if productVariantsBulkUpdate allowed us to set inventory quantities as well.

AsafGitai
Shopify Staff
109 16 45

Sorry, what i meant is that we can't look into why you received LOCATION_NOT_FOUND without knowing the actual info you sent instead of {{my_location_id}} & {{my_variant_inventory_item_id}}

PriLopes
Shopify Partner
13 0 16

Ah, okay.. sorry 😅

 

Here it is an example:

inventoryItemId: "gid://shopify/InventoryItem/47864330485986"
locationId: "gid://shopify/Location/77083803874"

 

cbella
Shopify Staff
3 2 1

This is an accepted solution.

Hello @PriLopes,

 

The reason you are receiving the `LOCATION_NOT_FOUND` error for that location is because the location is a fulfillment_service location that has `permitsSkuSharing` set to false.

The error message is misleading and we should have a better error code to make that clear. I will see to it that we clear up our error messaging there.

 

If you can modify the fulfillment service to have `permitsSkuSharing` set to true, then calling inventoryBulkToggleActivation should succeed.

 

When a fulfillment service has `permitsSkuSharing` set to false, it means that the inventory can only be stocked at that fulfillment service location and no other locations.

 

I hope that helps!

Let me know!

PriLopes
Shopify Partner
13 0 16

Hi @cbella 

 

All right! That did work! Thanks a lot!! 🎉


One last thing tho. Is there a way we can update all inventory levels at once? Otherwise, for a product with 100 variants it would mean 100 calls to activate inventory with inventoryBulkToggleActivation

PriLopes
Shopify Partner
13 0 16

@cbella any news on that? It is really taking a very long time to activate the inventory for all the variants running one by one. It would be really helpful for us to have the capability to activate the inventory for all the variants of a same product in a single call

AsafGitai
Shopify Staff
109 16 45
DavidT
Shopify Partner
38 2 15

> AFAIK calling productSet with MediaIds should leave the product with ONLY those ids ( meaning emove any ids not passed in) - let me know if that is not the case and we can look into it

 

Can this please be updated to respect the order of the media IDs, so they will be sorted as you provide? Also non-Image media IDs don't work, it says "invalid id".

QuickEdit - Bulk Product Edit - Quick and easy bulk editor for products and variants.
SafeShip - Address Validator - International address validation and PO box blocking at checkout for Shopify Plus merchants.
PriLopes
Shopify Partner
13 0 16

Hi @DavidT we wanted to send mediaSrc instead of mediaIds so we don't have to create them before we set the product. But regarding having to delete old media before, it will help. Thanks!

AsafGitai
Shopify Staff
109 16 45
stefanb1234
Shopify Partner
15 0 6

> We are also considering adding fileCreatre capabilities to productSet in the near future.

Is there a roadmap for that?

AsafGitai
Shopify Staff
109 16 45

can't commit just yet, but sooner than later 

johncmt
Tourist
9 0 2

Hi Asaf,

 

We want to report a bug in the productSet mutation relating to the new type FileSetInput.  We can reproduce it consistently and have sample files to share, but they contain URLs that we don't want to publicly share here.  We would be happy to send the files direct to you or the appropriate person on your team.

 

The gist of it is that if you call productSet to that includes images for both the product and one or more variants, then call productSet again with the same data, the images on the product get removed entirely.  If you call it again, they are added back.  Call it again and they are removed again.  So every other call to productSet will wipe out all images (both on the product and the variants).  We did it through 10 iterations and the cycle consistently repeats.

 

Thanks in advance for any insight or work on resolving this bug.

r_2_d_3
Visitor
1 0 0

Dear @AsafGitai , we also can reproduce the issue exactly as @johncmt described regarding the productSet mutation in combination with the files/[FileSetInput!]. It would be great if that bug could be resolved.