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.

Creating a Collection with a PRODUCT_TAXONOMY_NODE_ID Rule Fails

Solved

Creating a Collection with a PRODUCT_TAXONOMY_NODE_ID Rule Fails

Kris_Doyle
Shopify Partner
140 1 44

Hi All,

 

I have a simple GraphQL mutation below that seems to fail with the error "Collection could not be created":

 

mutation {
  collectionCreate(
    input: {
        title: "Taxonomy Test",
        sortOrder: BEST_SELLING,
        ruleSet: {
            appliedDisjunctively: true,
            rules: [{
                column: PRODUCT_TAXONOMY_NODE_ID,
                relation: EQUALS,
                condition: "1"
            }]
        }
}) { collection { id } } }

Every time I run it, I get this response:

{
  "data": {
    "collectionCreate": {
      "collection": null
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 10,
      "actualQueryCost": 10,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 990,
        "restoreRate": 50
      }
    }
  }
}

If I run this through the GraphQL Admin API I get "422 Unprocessable Entity", and "Collection could not be created" and I am struggling to understand what I'm doing wrong. I'm using API version 2022-10 so I know it's supported.

 

Anyone see something obvious I'm missing? Thanks!

Accepted Solution (1)

ShopifyDevSup
Shopify Staff
1453 238 531

This is an accepted solution.

Hi @Kris_Doyle,

 

Thanks for your post. To see the error message that explains why a 'null' response is being returned you can include the userErrors object with 'field' and 'message' in the return request just under where the collection id is being requested in the return like this:

 

 collection {
  id
 }
 userErrors {
  field
  message
 }

 

With that in there you'll find the error message talks about a missing ProductTaxonomyNode. For that the solution is to set the 'condition' to the ProductTaxonomyNode gid format instead of just the number, for example:

 

condition: "gid://shopify/ProductTaxonomyNode/1"

 

For reference the list of ProductTaxonomyNode id's with their titles in English can be found [at this link]. That link is also available on [this doc page about Product Taxonomy].

 

Hope you have a great day

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 5 (5)

Kris_Doyle
Shopify Partner
140 1 44

Just wanted to add that I've also tried this using the Shopify GraphQL App with the same result. No error message is returned, just a "null" for the collection ID.

Kris_Doyle
Shopify Partner
140 1 44

Another quick update on this...even though the create is failing and the returned ID is "null", the server is actually returning a "200 - OK". It's strange that it would return a 200 when the create fails. The 422 I mentioned above is actually an error code I return to the front end to alert the user...my bad on that, the code's been around a while now 😉

 

Anyhow, the issue is the same. There's no collection ID returned, and the response code is 200.

ShopifyDevSup
Shopify Staff
1453 238 531

This is an accepted solution.

Hi @Kris_Doyle,

 

Thanks for your post. To see the error message that explains why a 'null' response is being returned you can include the userErrors object with 'field' and 'message' in the return request just under where the collection id is being requested in the return like this:

 

 collection {
  id
 }
 userErrors {
  field
  message
 }

 

With that in there you'll find the error message talks about a missing ProductTaxonomyNode. For that the solution is to set the 'condition' to the ProductTaxonomyNode gid format instead of just the number, for example:

 

condition: "gid://shopify/ProductTaxonomyNode/1"

 

For reference the list of ProductTaxonomyNode id's with their titles in English can be found [at this link]. That link is also available on [this doc page about Product Taxonomy].

 

Hope you have a great day

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Kris_Doyle
Shopify Partner
140 1 44

Hello @ShopifyDevSup !

 

Thanks very much for this!

 

I think what was throwing me off, is that when you query a collection that uses taxonomy rules, the condition only returns "1", not the "gid" version as you have above.

 

So this query:

{
  collection(id: "gid://shopify/Collection/317816504515") {
    id
    ruleSet {
      rules {
        column
        relation
        condition
      }
    }
  }
}

 

Returns this:

{
  "data": {
    "collection": {
      "id": "gid://shopify/Collection/317816504515",
      "ruleSet": {
        "rules": [
          {
            "column": "PRODUCT_TAXONOMY_NODE_ID",
            "relation": "EQUALS",
            "condition": "1"
          }
        ]
      }
    }
  }
}

 

I think it would be better if the "condition" returned the taxonomy node in the "gid" format as you mentioned above "gid://shopify/ProductTaxonomyNode/1". I checked the docs but I wasn't able to see this anywhere. This makes sense though so obviously some learning on my part 🙂

 

Thanks for your help!

guest4
Shopify Partner
103 7 26

We'd like to make it abundantly clear for future readers that the GIDs for the predefined Product Taxonomy Nodes are determined by combining the string "gid://shopify/ProductTaxonomyNode/" with the numeric Id from the Shopify taxonomy (Reference: https://help.shopify.com/txt/product_taxonomy/en.txt).

 

If the numeric Id for the Electronics > Audio is 1275 then the GID is gid://shopify/ProductTaxonomyNode/1275.