getting parse error in bulk operation

getting parse error in bulk operation

akshuklait
Shopify Partner
6 0 2

Hi, 
I'm running into a bulk operation issue.  
I want to get all products from the Shopify store based on some product types, but not getting a proper response. Here I'm attaching 2 cases

 

Case 1: Adding all filter values without addslashes, this gives no error also not sending bulk operation URL

Request data

mutation {
                  bulkOperationRunQuery(
                    query:"""
                     {
                  products(query: "product_type:'Bags' OR product_type:'Men's Socks' OR product_type:'men's' OR product_type:'men's button-ups'") {
                    edges {
                      node {
                        id
                        title
                        vendor
                        productType                        
                        descriptionHtml
                        handle
                        tags   
                        publishedAt
                        createdAt
                        updatedAt                     
                        featuredImage {
                          id
                          originalSrc                          
                        }
                        images {
                          edges {
                            node {
                              id
                              originalSrc                              
                            }
                          }
                        }
                        collections {
                          edges {
                            node {
                              id
                              title
                            }
                          }
                        }
                        
                        variants {
                          edges {
                            node {
                              id
                              title
                              position
                              sku
                              price
                              compareAtPrice
                              inventoryQuantity
                              weight
                              weightUnit
                              barcode
                              inventoryPolicy
                              taxable
                              createdAt
                              updatedAt
                              fulfillmentService {
                                handle
                                serviceName
                              }
                              image {
                                id
                                originalSrc
                                transformedSrc
                              }
                              selectedOptions {
                                name
                                value
                              }
                              inventoryItem {
                                id
                                tracked
                                requiresShipping
                                inventoryLevels {
                                  edges {
                                    node {
                                      id
                                      available
                                      updatedAt
                                      location {
                                        id
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
            
                    """
                  ) {
                    bulkOperation {
                      id
                      status
                    }
                    userErrors {
                      field
                      message
                    }
                  }
                }
)

Response data

Array
        (
            [id] => gid://shopify/BulkOperation/321298235473
            [status] => COMPLETED
            [errorCode] => 
            [createdAt] => 2021-03-25T10:20:41Z
            [completedAt] => 2021-03-25T10:20:42Z
            [objectCount] => 0
            [fileSize] => 
            [url] => 
            [partialDataUrl] => 
        )

 

Case 2:  adding  addslashes between filter values


Request data

mutation {
                  bulkOperationRunQuery(
                    query:"""
                     {
                  products(query: "product_type:'Bags' OR product_type:'Men\'s Socks' OR product_type:'men\'s' OR product_type:'men\'s button-ups'") {
                    edges {
                      node {
                        id
                        title
                        vendor
                        productType                        
                        descriptionHtml
                        handle
                        tags   
                        publishedAt
                        createdAt
                        updatedAt                     
                        featuredImage {
                          id
                          originalSrc                          
                        }
                        images {
                          edges {
                            node {
                              id
                              originalSrc                              
                            }
                          }
                        }
                        collections {
                          edges {
                            node {
                              id
                              title
                            }
                          }
                        }
                        
                        variants {
                          edges {
                            node {
                              id
                              title
                              position
                              sku
                              price
                              compareAtPrice
                              inventoryQuantity
                              weight
                              weightUnit
                              barcode
                              inventoryPolicy
                              taxable
                              createdAt
                              updatedAt
                              fulfillmentService {
                                handle
                                serviceName
                              }
                              image {
                                id
                                originalSrc
                                transformedSrc
                              }
                              selectedOptions {
                                name
                                value
                              }
                              inventoryItem {
                                id
                                tracked
                                requiresShipping
                                inventoryLevels {
                                  edges {
                                    node {
                                      id
                                      available
                                      updatedAt
                                      location {
                                        id
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
            
                    """
                  ) {
                    bulkOperation {
                      id
                      status
                    }
                    userErrors {
                      field
                      message
                    }
                  }
                }
)

Response data

[errors] => Array
        (
            [0] => Array
                (
                    [message] => Parse error on bad Unicode escape sequence: "     {\n  products(query: \"product_type:'Bags' OR product_type:'Men\\'s Socks' OR product_type:'men\\'s' OR product_type:'men\\'s button-ups'\") {\n    edges {\n      node {\n        id\n        title\n        vendor\n        productType                        \n        descriptionHtml\n        handle\n        tags   \n        publishedAt\n        createdAt\n        updatedAt                     \n        featuredImage {\n          id\n          originalSrc                          \n        }\n        images {\n          edges {\n            node {\n              id\n              originalSrc                              \n            }\n          }\n        }\n        collections {\n          edges {\n            node {\n              id\n              title\n            }\n          }\n        }\n        \n        variants {\n          edges {\n            node {\n              id\n              title\n              position\n              sku\n              price\n              compareAtPrice\n              inventoryQuantity\n              weight\n              weightUnit\n              barcode\n              inventoryPolicy\n              taxable\n              createdAt\n              updatedAt\n              fulfillmentService {\n                handle\n                serviceName\n              }\n              image {\n                id\n                originalSrc\n                transformedSrc\n              }\n              selectedOptions {\n                name\n                value\n              }\n              inventoryItem {\n                id\n                tracked\n                requiresShipping\n                inventoryLevels {\n                  edges {\n                    node {\n                      id\n                      available\n                      updatedAt\n                      location {\n                        id\n                      }\n                    }\n                  }\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}\n\n    " (error) at [3, 27]
                    [locations] => Array
                        (
                            [0] => Array
                                (
                                    [line] => 3
                                    [column] => 27
                                )

                        )

                )

        )

 

Please let me know a possible solution asap, I can't find what I'm missing here.

 

Thanks

Reply 1 (1)

syf_
Shopify Staff
95 21 25

@akshuklait since you have apostrophes in there, I think it would be best to use escaped double quotes on your search strings. For example use \"Men's Socks\" instead of 'Men's Socks' or 'Men\'s Socks'

Best,
Seth.

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