Discuss all the new features introduced with the new product model in GraphQL.
I'm migrating some existing GraphQL code that is no longer compatible with the new 2024-04 API.
My requirements are:
Before, I was able to achieve what I needed in 2 GraphQL API Calls:
1. productCreate: I created the product with the inventoryItem > tracked: True flag, SKU, and inventory Quantities for a non default Inventory Location.
2. publishablePublish: Published the product to the Online Store and Point of Sale sales channels. Later when the product status is changed to Active, these Sales Channels are already enabled.
With the 2024-04 API Changes, it seems that I need to make 5 API Calls:
1. productCreate: I can no longer specify any variant information, so the product cannot be marked as tracked by inventory or with a SKU.
2. inventoryActivate: For the default product variant InventoryItem, I activate an Inventory Location that is not enabled by default.
3. productVariantUpdate: For the default product variant, I add the SKU, taxable: True, inventoryItem > tracked: true. Here, if I add inventoryQuantities as part of the mutation input, it doesn't modify the available quantity or come back with an error. The rest of the data is updated Ok. Is this a bug?
4. inventorySetOnHandQuantities: For the default product variant InventoryItem, I set the quantity to 1.
5. publishablePublish: I publish the product to the Online Store and Point of Sale sales channels.
Am I approaching this the correct way? Or would there be a better way to achieve my requirements with the new API?
5 API calls seems an exaggerate number to add one product with the desired properties. Also, there's a higher probability of API transient errors to break the expected functionality (e.g.: Adding the product, but not assigning inventory quantities).
Thanks!
Solved! Go to the solution
This is an accepted solution.
I ran into this today as well. Here is the solution:
1. Do a productCreate
2. Do a productVariantBulkCreate with one single variant and strategy REMOVE_STANDALONE_VARIANT
Works like a charm
This is an accepted solution.
I ran into this today as well. Here is the solution:
1. Do a productCreate
2. Do a productVariantBulkCreate with one single variant and strategy REMOVE_STANDALONE_VARIANT
Works like a charm
Thanks!.. This worked 😎
What' the query look like?
These are how my mutations look like:
mutation productCreate($input: ProductInput!) {
productCreate(input: $input) {
product {
id
}
userErrors {
field
message
}
}
}
{
"input": {
"title": "Product Title",
"productType": "Product X",
"vendor": "Vendor X",
"descriptionHtml": "Product description",
"status": "DRAFT",
"metafields": [
{
"namespace": "custom_fields",
"key": "my_custom_field",
"type": "single_line_text_field",
"value": "Some value.."
}
]
}
}
-------------
Then using the productId generated by the previous mutation:
mutation productVariantsBulkCreate($productId: ID!, $strategy: ProductVariantsBulkCreateStrategy, $variants: [ProductVariantsBulkInput!]!) {
productVariantsBulkCreate(productId: $productId, strategy: $strategy, variants: $variants) {
product {
id
}
userErrors {
field
message
}
}
}
{
"productId": "gid://shopify/Product/123456789",
"strategy": "REMOVE_STANDALONE_VARIANT",
"variants": [
{
"inventoryItem": {
"requiresShipping": true,
"tracked": true
},
"inventoryPolicy": "DENY",
"inventoryQuantities": [
{
"availableQuantity": 1,
"locationId": "gid://shopify/Location/123456789"
},
{
"availableQuantity": 0,
"locationId": "gid://shopify/Location/987654321"
}
],
"sku": "SKU_ABC",
"taxable": true
}
]
}
Hope this helps..
keep getting post Response Logging: {"errors":[{"message":"Variable $productId of type ID! was provided invalid value","locations":[{"line":2,"column":68}],"extensions":{"value":null,"problems":[{"path":[],"explanation":"Expected value to not be null"}]}},{"message":"Variable $variants of type [ProductVariantsBulkInput!]! was provided invalid value","locations":[{"line":2,"column":85}],"extensions":{"value":null,"problems":[{"path":[],"explanation":"Expected value to not be null"}]}}]} bookdelivered.myshopify.com error. Please help
Does your productId start with gid://shopify/Product ?