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.

Graph QL inventory query

Graph QL inventory query

jeremyha_1
Shopify Partner
3 0 1

Would like to build a graphQL query to list all Products, barcodes and their quantities.Ideally want to export the results to a spreadsheet. Very new to GraphQL but starting to write simple queries but lost on where to get quantity information. 

Replies 4 (4)

CloudlabSam
Shopify Partner
604 49 105

You can get the quantity information from the inventory item or inventory level, depending on if you have different inventory locations.

 

There are lots of low cost apps that will allow you to get this information. Better Reports, Report Toaster, etc.

ShopifyDevSup
Shopify Staff
1453 238 527

Hi @jeremyha_1 

You can get this information via the GraphQL Admin API in a few different ways. It's important to know that the barcode and inventory quantity are stored in the product variants that exist for each product. Additionally using the GraphQL Admin API to retrieve this data will return it in a json object, if you require it in a spreadsheet you will need to parse the response data you receive with your own applications code.

First you can retrieve this data by querying the Products object, this will retrieve a list of products, and all the product variant's within that product. Here's an example query and the corresponding Shopify.dev documentation:
 

query {

    products(first: 50) {

        nodes{

            title

            id

            variants(first: 50){

                nodes{

                    title

                    barcode

                    inventoryQuantity

                }

            }

        }

    }

}

As mentioned you can also retrieve this data by query for product variants directly like so:

 

query {

    productVariants(first: 50){

        edges {

            node {

                displayName

                barcode

                inventoryQuantity

            }

        }

   }

}

It's also important to know that when querying large amounts of data with GraphQL you are limited to only retrieving up to 250 items at a time, though we do suggest querying less to prevent any timeouts from occurring when making queries that is retrieving lots of data. If you are needing to retrieve more than 250 items at once, you can use pagination to retrieve your items in batches. 

Additionally if you need to request a lot of data at once, you can also use Bulk Operations to export as many items as required all in one operation. This will also prevent your app from hitting any api rate limits you might experience when using pagination too quickly.

Here are some more helpful Shopify.dev documentation on Paginating results, Bulk Operations, and some general guidance on using GraphQL overall.

 

I hope this all helps, and I hope you have a great day 🙂

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

jeremyha_1
Shopify Partner
3 0 1

That’s really helpful. Thank you very much

Kalen_Jordan
Shopify Partner
800 38 144

Our app mesa has a custom code feature that you could use to do this and a google sheets integration.