"expected String to be a Hash" Question

When registering a product with the “productCreate GraphQL API”, the response is “expected String to be a Hash”. I’d like to ask you what to do.

{
  "query": "mutation productCreate($input: ProductInput!) {\n  productCreate(input: $input) {\n    product {      \n      id\n      descriptionHtml\n      featuredImage{        \n          url          \n      }      \n      title      \n      vendor\n      productType\n      hasOnlyDefaultVariant  \n      onlineStorePreviewUrl\n      onlineStoreUrl\n      priceRangeV2{\n          maxVariantPrice{\n              amount\n              currencyCode\n          }\n          minVariantPrice{\n              amount\n              currencyCode\n          }\n      }\n      productCategory{\n          productTaxonomyNode{\n              fullName\n              id\n              name\n          }\n      } \n      tags\n      status\n      totalVariants\n      tracksInventory\n    }    \n    userErrors {\n      field\n      message\n    }\n  }\n}",
  "variables": "{\n\t\"input\": {\n\t\t\"collectionsToJoin\": [\n\t\t\t\"gid://shopify/Collection/459616092460\"\n\t\t],\n\t\t\"collectionsToLeave\": [\n\t\t\t\"gid://shopify/Collection/459616092460\"\n\t\t],\n\t\t\"descriptionHtml\": \"\\r\\n123\",\n\t\t\"images\": [\n\t\t\t{\n\t\t\t\t\"altText\": null,\n\t\t\t\t\"src\": \"https://sellpick-bucket.s3.ap-northeast-2.amazonaws.com/dev/upload/file/BACD0420/weap0n77/191655/20231023151031/3a84c1df3a49c77ac707.JPG\"\n\t\t\t}\n\t\t],\n\t\t\"metafields\": [\n\t\t\t{\n\t\t\t\t\"id\": null,\n\t\t\t\t\"description\": null,\n\t\t\t\t\"key\": \"use1\",\n\t\t\t\t\"namespace\": \"custom\",\n\t\t\t\t\"type\": \"multi_line_text_field\",\n\t\t\t\t\"value\": \"메타11112\"\n\t\t\t}\n\t\t],\n\t\t\"options\": [\n\t\t\t\"색상\"\n\t\t],\n\t\t\"productCategory\": {\n\t\t\t\"productTaxonomyNodeId\": \"gid://shopify/ProductTaxonomyNode/1\"\n\t\t},\n\t\t\"productType\": \"구두2\",\n\t\t\"status\": \"ACTIVE\",\n\t\t\"tags\": [\n\t\t\t\"tag1\",\n\t\t\t\"tag2\"\n\t\t],\n\t\t\"title\": \"테스트테스트1111\",\n\t\t\"productPublications\": [\n\t\t\t{\n\t\t\t\t\"channelId\": \"gid://shopify/Channel/199319355692\"\t\t\t\t\n\t\t\t}\n\t\t]\n\t}\n}"
}

Hi Weap0n7,

The error message “expected String to be a Hash” usually indicates that the GraphQL server is expecting a JSON object (Hash in Ruby) but it’s receiving a string.

Looking at your “variables” field in the request, it seems like it’s a string of a JSON, not a JSON object itself.

Here is the problematic part:

"variables": "{\n\t\"input\": {\n\t\t\"collectionsToJoin\": [\n\t\t\t\"gid://shopify/Collection/459616092460\"\n\t\t],\n\t\t\"collectionsToLeave\": [\n\t\t\t\"gid://shopify/Collection/459616092460\"\n\t\t],\n\t\t\"descriptionHtml\": \"\\r\\n123\",\n\t\t\"images\": [\n\t\t\t{\n\t\t\t\t\"altText\": null,\n\t\t\t\t\"src\": \"https://sellpick-bucket.s3.ap-northeast-2.amazonaws.com/dev/upload/file/BACD0420/weap0n77/191655/20231023151031/3a84c1df3a49c77ac707.JPG\"\n\t\t\t}\n\t\t],\\t\t\"metafields\": [\n\t\t\t{\n\t\t\t\t\"id\": null,\n\t\t\t\t\"description\": null,\n\t\t\t\t\"key\": \"use1\",\n\t\t\t\t\"namespace\": \"custom\",\n\t\t\t\t\"type\": \"multi_line_text_field\",\n\t\t\t\t\"value\": \"메타11112\"\n\t\t\t}\n\t\t],\n\t\t\"options\": [\n\t\t\t\"색상\"\n\t\t],\n\t\t\"productCategory\": {\n\t\t\t\"productTaxonomyNodeId\": \"gid://shopify/ProductTaxonomyNode/1\"\n\t\t},\n\t\t\"productType\": \"구두2\",\n\t\t\"status\": \"ACTIVE\",\n\t\t\"tags\": [\n\t\t\t\"tag1\",\n\t\t\t\"tag2\"\n\t\t],\n\t\t\"title\": \"테스트테스트1111\",\\t\t\"productPublications\": [\n\t\t\t{\n\t\t\t\"channelId\": \"gid://shopify/Channel/199319355692\"\t\t\t\t\n\t\t\t}\n\t\t]\n\t}\n}"

You need to pass the JSON object directly, like so:

"variables": {
  "input": {
    "collectionsToJoin": [
      "gid://shopify/Collection/459616092460"
    ],
    "collectionsToLeave": [
      "gid://shopify/Collection/459616092460"
    ],
    "descriptionHtml": "\r\n123",
    "images": [
      {
        "altText": null,
        "src": "https://sellpick-bucket.s3.ap-northeast-2.amazonaws.com/dev/upload/file/BACD0420/weap0n77/191655/20231023151031/3a84c1df3a49c77ac707.JPG"
      }
    ],
    "metafields": [
      {
        "id": null,
        "description": null,
        "key": "use1",
        "namespace": "custom",
        "type": "multi_line_text_field",
        "value": "메타11112"
      }
    ],
    "options": [
      "색상"
    ],
    "productCategory": {
      "productTaxonomyNodeId": "gid://shopify/ProductTaxonomyNode/1"
    },
    "productType": "구두2",
    "status": "ACTIVE",
    "tags": [
      "tag1",
      "tag2"
    ],
    "title": "테스트테스트1111",
    "productPublications": [
      {
        "channelId": "gid://shopify/Channel/199355692"
      }
    ]
  }
}

Make sure you are passing a object for the variables field, not a string representation of the JSON object.

Try out the above and hopefully this will fix the issue.