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

CollectionToJoin on CreateProductMutation not working

CollectionToJoin on CreateProductMutation not working

Dyllanjr
Shopify Partner
2 0 0

Hello, I have a mutation that looks like this

 

mutation {
  productCreate(
    input: {
      handle: "closeout-50-off-ls2-bagger-solid-gloss-black-half-helmet",
      title: "CLOSEOUT 50% OFF LS2 Bagger Solid Gloss Black Half Helmet",
      productType: "",
      vendor: "LS2",
      tags: ["Brand_LS2", "Open Box", "Product Type_SALE", "Sale"],
      productOptions: [
        {
          name: "Size",
          values: [
            { name: "XS" },
            { name: "S" },
            { name: "XL" }
          ],
          position: 1
        }
      ]
    },
    collectionsToJoin: [
      "gid://shopify/Collection/285094805592",
      "gid://shopify/Collection/285093593176",
      "gid://shopify/Collection/285091528792",
      "gid://shopify/Collection/286035017816"
    ]
  ) {
    product {
      id
      title
    }
    userErrors {
      field
      message
    }
  }
}

 

 

And the collections aren't being added to the product. The collections exist and the collection id's are correct. Any help would be greatly appreciated!

Reply 1 (1)

Liam
Community Manager
3108 344 910

Hi Dyllanjr,

 

If you try with adding the product to just one collection, is it still not working? Also - are the collections you're referencing manual or automated collections? It's possible if the product doesn't meet conditions in an automated collection the product won't be added. I can confirm this simpler mutation worked for me when adding to a manual collection:

 

mutation CreateProduct {
  productCreate(input: {
    title: "Newer Product",
    descriptionHtml: "<p>This is a nice new product.</p>",
    collectionsToJoin: "gid://shopify/Collection/476864020783"
  }) {
    product {
      id
      title
    }
    userErrors {
      field
      message
    }
  }
}

 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me 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