graphql - Shopify-Bulk query to get all the products details
I have a requirement of getting all the products details(i want every detail like id,body,title,vendor,body_html,product_type etc of the each product) from a particular shop in shopify .I want to get same data as we get in ('/products.json?limit=250') Admin API request .I wanted to use bulk query to solve this.i have gone through the shopify Admin GraphQl API Docs. I was not able to find a query which will give all the product details in the shop.
I have tried below query.
query = '''
mutation {
bulkOperationRunQuery(
query : """
{
products {
edges {
node {
id
title
vendor
}
}
}
}
"""
){
bulkOperation {
id
status
}
userErrors {
field
message
}
}
}'''
shopify.GraphQL().execute(query)
the above query is executing properly. I am getting the below success response.
'{"data":{"bulkOperationRunQuery":{"bulkOperation":{"id":"gid:\/\/shopify\/BulkOperation\/2061234200041","status":"CREATED"},"userErrors":[]}},"extensions":{"cost":{"requestedQueryCost":10,"actualQueryCost":10,"throttleStatus":{"maximumAvailable":1000.0,"currentlyAvailable":990,"restoreRate":50.0}}}}'
but when i add extra field like product_type then it throwing me an error.
query = '''
mutation {
bulkOperationRunQuery(
query : """
{
products {
edges {
node {
id
title
vendor
product_type
}
}
}
}
"""
){
bulkOperation {
id
status
}
userErrors {
field
message
}
}
}'''
#print(query)
shopify.GraphQL().execute(query)
output:
'{"data":{"bulkOperationRunQuery":{"bulkOperation":null,"userErrors":[{"field":["query"],"message":"Invalid bulk query: Field 'product_type' doesn't exist on type 'Product'"}]}},"extensions":{"cost":{"requestedQueryCost":10,"actualQueryCost":10,"throttleStatus":{"maximumAvailable":1000.0,"currentlyAvailable":990,"restoreRate":50.0}}}}'
As anyone used bulk query to get all the products details from shopify for particular store? if yes , would you help me by posting the query here.
Answer
Solution:
You made a simple mistake. You slipped into the coma world of snake case versus camel case. Our overlords of JS love that.
In GraphQL world, it would be productType, not product_type.
Why we waste billions of dollars on broken software often boils down to these things. Yay!
Source
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.