When I create a variant in the GraphQL API productVariantsBulkCreate endpoint, the inventory set in the request parameter is 0, but the variant inventory is not 0 in the response parameter of the Get Product interface. Does anyone know why this is? Thanks for your guidance!
This is the parameter information I used, you can use it as a reference.
{
"productId": "gid://shopify/Product/xxxxxx",
"strategy": "REMOVE_STANDALONE_VARIANT",
"variants": [
{
"price": 45,
"compareAtPrice": 50,
"barcode": "291408",
"optionValues": {
"optionName": "Title",
"name": "Default Title"
},
"taxCode": "FR_FR_STANDARD_RATE",
"inventoryPolicy": "CONTINUE",
"taxable": true,
"inventoryItem": {
"sku": "291408",
"tracked": true,
"measurement": {
"weight": {
"value": 0,
"unit": "KILOGRAMS"
}
}
},
"inventoryQuantities": [
{
"availableQuantity": 10,
"locationId": "gid://shopify/Location/10071ssssss"
}
]
}
]
}
Thank you for the parameter example you provided. My request parameters are the same as yours, except that my availableQuantity is set to 0. My steps are to execute the CreateProductVariants interface first, and then set the inventory through the inventorySetQuantities interface. However, after executing the CreateProductVariants interface, I found that the inventory of the variant is 34, which is very strange. I don’t know where the problem is. Did you set 10 inventory quantities when creating the variant through the CreateProductVariants endpoint? Can your inventory be set successfully?
I have no problem using the inventorySetQuantities API,
These apis are successfully called by me in the actual business.
mutation inventorySetQuantities($input: InventorySetQuantitiesInput!) {
inventorySetQuantities(input: $input) {
inventoryAdjustmentGroup {
id
createdAt
changes{
quantityAfterChange
delta
item{
id
inventoryLevel(locationId:"gid://shopify/Location/1007werwerwer"){
id
item{
createdAt
}
}
}
}
}
userErrors {
field
message
}
}
}
{
"input": {
"name":"available",
"reason":"correction",
"ignoreCompareQuantity":true,
"quantities": [
{
"inventoryItemId": "gid://shopify/InventoryItem/5219xxxxxxxx",
"quantity": 10,
"locationId": "gid://shopify/Location/1007xxxxxx"
},
{ "inventoryItemId": "gid://shopify/InventoryItem/518xxxxxx",
"quantity": 90,
"locationId": "gid://shopify/Location/1007xxxxxx"
}
]
}
}
When I requested CreateProductVariants, the inventory was already 34, but the inventory I gave when requesting the CreateProductVariants interface was 0,
QUERY:
mutation CreateProductVariants($productId: ID!, $variantsInput: [ProductVariantsBulkInput!]!) {
productVariantsBulkCreate(productId: $productId, variants: $variantsInput) {
productVariants {
id
title
sku
barcode
position
price
compareAtPrice
taxable
selectedOptions {
name
value
}
inventoryItem {
id
}
inventoryPolicy
inventoryQuantity
}
userErrors {
field
message
}
}
}
GRAPHQL VARIABLES:
{
“productId”: “gid://shopify/Product/881xxxxxxxxxx”,
“variantsInput”: [{
“compareAtPrice”: 24.09,
“inventoryItem”: {
“cost”: 9.7,
“requiresShipping”: true,
“sku”: “A_M_NUB”,
“tracked”: true
},
“inventoryPolicy”: “DENY”,
“inventoryQuantities”: [
{
“availableQuantity”: 0,
“locationId”: “gid://shopify/Location/793xxxxxxxxxx”
}
],
“mediaId”: “gid://shopify/MediaImage/354xxxxxxxxxx”,
“optionValues”: [
{
“name”: “Cracker khaki”,
“optionName”: “Color”
},
{
“name”: “M”,
“optionName”: “Size”
}
],
“price”: 19.24,
“taxable”: false
}]
}
The inventorySetQuantities interface has not been requested yet.
Speaking of the inventorySetQuantities interface, how many items of inventory do you usually submit together in your actual scenarios? When I set up 20 variant inventory batch submissions, I found that some inventory was not set successfully, but Postman could set the inventory of these 20 items separately. Is it because I requested several interfaces in succession in the code and reached the interface frequency limit of Shopify? However, I checked the values of currentlyAvailable in the interface response parameter extensions, which are basically 1979~1989, which makes me very confused. I don’t know how to control this interface frequency. How do you solve this problem?
You can consider processing the timing of the next request based on the value of ‘currentlyAvailable’, for example, when ‘currentlyAvailable’ becomes a very small value of 100, sleep the program for a period of time (0.5 seconds)
I haven’t updated 20 at once like you did.
For example, if a new product is added, but this product has 50 variants, do you set the inventory quantity asynchronously? How many variants of inventory do you usually submit at a time?