platformOS Community

Using properties in [CustomizationImport!]! mutation

Matt Jones Mar 10 2021 at 10:51

Trying to import the following data (which was originally JSON, but has since been through parse_json filter and then logged):

[{"type_name":"module_14/attribute","id":"7501355","properties":[{"name":"name","value":"Your Chosen Size"},{"name":"enabled","value":true},{"name":"module_field_14/product_attribute_1","value":"4161"}]},{"type_name":"module_14/product_attribute_option","id":"49443398","properties":[{"name":"name","value":"24\" x 24\""},{"name":"enabled","value":"true"},{"name":"module_field_14/product_attribute_option_1","value":"7501355"},{"name":"module_field_14/product_attribute_option_2","value":"0"}]}]

Using the mutation:

{% graphql g, data: params.data %}
  mutation import_attributes($data: [CustomizationImport!]!) {
    import_models(models: $data, _index_rebuild: true) {
      ids
    }
  }
{% endgraphql %}

But I don't understand the error message:
GraphQL Error: Variable $data of type [CustomizationImport!]! was provided invalid value for 0.properties (Can not coerce... to HashObject.) I understand from experimentation and the message that the problem is the properties key and its array value, but I don't understand what the correct format should be or how to get to that format using Liquid filters- I would assume a parse_json filter should do this for me?

Thanks,

Matt Jones Mar 11 2021 at 16:36

Worked it out- but will post the answer in case anyone else is confused by this:
(Variables Panel)

{
"data": [
    {
			"type_name":"module_14/product_attribute",
      "id":7501355,
			"properties": {
				"name":"Your Chosen Size",
				"enabled":true,
				"module_field_14/product_attribute_1":"4161"
      }
		}
  ]
}

Essentially, the properties array needs to be treated like an object when it is a variable being fed into [CustomizationImport!]!.

Please sign in or fill up your profile to answer a question