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: %}
  mutation import_attributes($data: [CustomizationImport!]!) {
    import_models(models: $data, _index_rebuild: true) {
{% endgraphql %}

But I don't understand the error message:
GraphQL Error: Variable $data of type [CustomizationImport!]! was provided invalid value for (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?


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": [
			"properties": {
				"name":"Your Chosen Size",

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