"Unexpected file structure - expected JSONL" error when creating a metafieldsSet bulk operation

Hi,

I’m having problems creating a bulkOperationRunMutation request for a metafieldsSet operation. I’m following these instructions, and the API version being used is 2022-10.

I always get this error when running the bulkOperationRunMutation GraphQL request:

Unexpected file structure - expected JSONL

First of all, I’m not sure if the metafieldsSet operation is supported to run with bulkOperationRunMutation.

On the limitations section it does list metafieldsSet, so I would think it is supported. But on the Create a bulk operation mutation section, in the mutation parameter description it shows:

Specifies the GraphQL API mutation that you want to run in bulk. Valid values: productCreate, collectionCreate, productUpdate, productUpdateMedia, productVariantUpdate

So by reading this, it would seem that metafieldsSet is not supported. Would this explain the error? :thinking:

I’m able to successfully run the example bulk mutation for productCreate - No errors here.

Since I’m doing initial testing, I’m only including one line in the JSONL file. I’ve tried these (and more) combinations:

{ "metafields": { "key": "has_sim_card_option", "value": "false", "namespace": "custom_fields", "ownerId": "gid://shopify/Product/22930626609410", "type": "boolean" } }
{ "key": "has_sim_card_option", "value": "false", "namespace": "custom_fields", "ownerId": "gid://shopify/Product/22930626609410", "type": "boolean" }

The GraphQL command:

mutation {
	bulkOperationRunMutation(
		mutation: "mutation metafieldsSet($metafields: [MetafieldsSetInput!]!) { metafieldsSet(metafields: $metafields) { metafields { key namespace value createdAt updatedAt } userErrors { field message }	} }",
		stagedUploadPath: "tmp/gcs/123456789/bulk/replaced-just-in-case-abcde/metafields.jsonl"
		    
	) {
		bulkOperation {
			id
			status
		}
		userErrors {
			field
			message
		}
	}
}

Any assistance is appreciated, as it would be great if I could run the data changes in bulk.

Thanks!

Not sure what happened, but it’s now working. :grin:

One thing I did notice is that I had the incorrect gid # in the JSONL file. Instead of using the productid I was using the metafield id.

So what worked for me was:

JSONL File example:

{"metafields":{ "key": "has_sim_card_option", "value": "false", "namespace": "custom_fields", "ownerId": "gid://shopify/Product/7838835933442", "type": "boolean" }}

GraphQL Command:

mutation {
	bulkOperationRunMutation(
		mutation: "mutation metafieldsSet($metafields: [MetafieldsSetInput!]!) { metafieldsSet(metafields: $metafields) { metafields { key namespace value createdAt updatedAt } userErrors { field message }	} }",
		stagedUploadPath: "tmp/gcs/123456789/bulk/replaced-just-in-case-abcde/metafields.jsonl"
		    
	) {
		bulkOperation {
			id
			status
		}
		userErrors {
			field
			message
		}
	}
}

I would recommend updating the documentation so that the mutation parameter description lists all the supported operations, including metafieldsSet.