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.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

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

Solved

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

Juanespty
Shopify Partner
7 2 4

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? 🤔

 

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!

Accepted Solution (1)

Juanespty
Shopify Partner
7 2 4

This is an accepted solution.

Not sure what happened, but it's now working. 😁

 

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.

 

 

View solution in original post

Reply 1 (1)

Juanespty
Shopify Partner
7 2 4

This is an accepted solution.

Not sure what happened, but it's now working. 😁

 

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.