Solved

graphql query to bulk create variants with option, price, inventory_management, fullfillment_service

techticmukesh
Shopify Partner
1 0 0

i am looking for query schema how to create variants in bulk via graphql api i tried but its giving errors on syntax when i include the required fields to the schema. The data i need to pass is 
variants [

     {
         option1: 'string',
         price: number,
         inventory_management: null,
         fulfillment_service: 'manual'
     }

]

Accepted Solution (1)

ShopifyDevSup
Shopify Staff
1367 228 479

This is an accepted solution.

Hey @techticmukesh

Taking a closer look at the docs for the productVariantBulkCreate mutation and the ProductVariantsBulkInput input object, these are probably the place to start working from. While I can't provide specifics for how this can be implemented in your code, the first doc does have examples you can build from if you are using one of our Support API libraries (Ruby, PHP, Node.js), in addition to raw GraphQL examples. 

I was able to do some testing and had great success working from the examples provided as a base. If you are using API version 2022-07 or later, you can use the mutation to set both the InventoryItemInput.tracked to set a value of true, and ProductVariantsBulkInput.inventoryQuantities InventoryLevelInput to set the locationId of the fulfillment service you wish to handle inventory and fulfillment. 

The doc also goes over this in greater detail, outlining the deprecated FulfillmentServiceId field that was previously used for the input. It expands on the change, with links to a number helpful resources and guides that cover an overview for current workflows of apps that handle inventory management as well as for fulfillment services - see image below.




My final suggestion here would be to consider using an API client like Insomnia or Postman for further exploration with structuring and testing the GraphQL APIs. I hope this info helps point you towards the solution you're building!

Cheers - @awwdam 
Shopify Developer Support
 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

View solution in original post

Reply 1 (1)

ShopifyDevSup
Shopify Staff
1367 228 479

This is an accepted solution.

Hey @techticmukesh

Taking a closer look at the docs for the productVariantBulkCreate mutation and the ProductVariantsBulkInput input object, these are probably the place to start working from. While I can't provide specifics for how this can be implemented in your code, the first doc does have examples you can build from if you are using one of our Support API libraries (Ruby, PHP, Node.js), in addition to raw GraphQL examples. 

I was able to do some testing and had great success working from the examples provided as a base. If you are using API version 2022-07 or later, you can use the mutation to set both the InventoryItemInput.tracked to set a value of true, and ProductVariantsBulkInput.inventoryQuantities InventoryLevelInput to set the locationId of the fulfillment service you wish to handle inventory and fulfillment. 

The doc also goes over this in greater detail, outlining the deprecated FulfillmentServiceId field that was previously used for the input. It expands on the change, with links to a number helpful resources and guides that cover an overview for current workflows of apps that handle inventory management as well as for fulfillment services - see image below.




My final suggestion here would be to consider using an API client like Insomnia or Postman for further exploration with structuring and testing the GraphQL APIs. I hope this info helps point you towards the solution you're building!

Cheers - @awwdam 
Shopify Developer Support
 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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