bulkOperationRunMutation generates "Unexpected file structure - expected JSONL" Error

New Member
2 0 0

How do we run bulkOperationRunMutation with nested data? 

The following bulk mutation works with the simple set of inputs that only contain titles.  However, it fails with the message "Unexpected file structure - expected JSONL" when we try to provide "input" containing the nested "ruleSet" objects in each JSONL line.  CollectionInput! defines ruleSet as a field, so we should be able to include that data for processing.

mutation {bulkOperationRunMutation (mutation: "mutation call ($input: CollectionInput!) { collectionCreate(input: $input) { collection {id title} userErrors {field message} } }", stagedUploadPath: "[STAGED_UPLOAD_PATH]"){bulkOperation {id status}userErrors {field message}}}

Simple Inputs (operation succeeds):

{"input":{"title":"Collection Title 1"}}
{"input":{"title":"Collection Title 2"}}

Nested Inputs (operation fails with "Unexpected file structure - expected JSONL" error):

{"input":{"title":"Collection Title 1","ruleSet":{"appliedDisjunctively":true,"rules":[{"column":TAG,"condition":"Collection Title 1","relation":EQUALS}]}}}
{"input":{"title":"Collection Title 2","ruleSet":{"appliedDisjunctively":true,"rules":[{"column":TAG,"condition":"Collection Title 2","relation":EQUALS}]}}}

Shopify Staff
Shopify Staff
92 10 4

Hey @jonh11

Having taken a bit of time to look through the info you shared concerning an error, my team and I were able to isolate a few formatting flags on the inputs that would explain why this error is being returned. The example inputs would need to follow the correct GraphQL syntax, specifically for string type. In this case, wrapping both values with "" for the "column" and "relation" values should correct the error.

I am going to submit a request to have our team review the documentation provided for stagedUploadsCreate and bulkOperationRunMutation, in the case that additional clarification is required. Below are a few visual examples that outline the functionality mentioned above - Cheers!

  • Example that was generating the error: [{"column":TAG,"condition":"Collection Title 1","relation":EQUALS}]}}} 


  • Adding the quotes to the input values in the Shopify GraphiQL explorer shows the syntax errors for both values - this is a great tool for testing and confirming GraphQL syntax!

  • Example updated with wrapped values:[{"column":"TAG","condition":"Collection Title 1","relation":"EQUALS"}]}}}   


awwdam | API 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

New Member
2 0 0

Thank you for the help!

We originally developed our CollectionInput JSON formatting for use with a single call to the collectionCreate mutation.  That call requires the column and relation values to be unquoted, whereas in a bulk mutation they must be quote delimited.  

It is a little tough to catch initially when keys and values should be quote delimited vs not, so any further documentation you can add about the different scenarios would definitely help others!