Have your say in Community Polls: What was/is your greatest motivation to start your own business?

GraphQL 2024-04 productCreate options only saving first option

Solved

GraphQL 2024-04 productCreate options only saving first option

Tozell
Shopify Partner
11 0 4

I've been going in circles trying to figure out why my code is receiving response 200 and my product is created yet all options after the first in the array are ignored. My submission is as follows:

 

mutation { productCreate(input: {title: "test productCreate run 1", descriptionHtml: "<h1>Test Product via productCreate</h1><p>some text here</p>", tags: "test,productCreate,tags1", status: DRAFT, productOptions: [{ name: "Colour", position: 1, values: [ { name: "Green" }, { name: "Red" }, { name: "Blue" }, { name: "Purple" } ] }, { name: "Holes", position: 2, values: [ { name: "No hole" }, { name: "1 Hole" }, { name: "2 Holes" } ] }] }){ product { id } } }

 

I receive the product ID back correctly yet when I view the product in my admin I only see:

  • "Colour" option "Green" 
  • "Holes" option "No hole"

All my other options on both sets are ignored entirely. There are other similar posts to this but not in the correct forum sections and their questions have zero answer ( https://community.shopify.com/c/shopify-discussions/latest-admin-graphql-api-not-working-properly/m-... )

 

Can anyone chime in as to why I get zero errors yet clearly have errors or something is going wrong at the gateway side. Thank you.

Accepted Solution (1)

jamalsoueidan
Shopify Partner
66 3 8

This is an accepted solution.

I tried your graphql, and also the example here:

https://shopify.dev/docs/api/admin-graphql/2024-04/mutations/productCreate?example=Create+a+product+...

 

It seems you must have a variant for the product with those options before they are visible, they are created on the product, but in the UI you cannot see them until you have options with those values.

 

 

mutation CreateProductWithOptions($input: ProductInput!) {
  productCreate(input: $input) {
    userErrors {
      field
      message
    }
    product {
      id
      options {
        id
        name
        position
        values
        optionValues {
          id
          name
          hasVariants
        }
      }
      variants(first: 5) {
        nodes {
          id
          title
          selectedOptions {
            name
            value
          }
        }
      }
    }
  }
}

 

View solution in original post

Replies 3 (3)

jamalsoueidan
Shopify Partner
66 3 8

This is an accepted solution.

I tried your graphql, and also the example here:

https://shopify.dev/docs/api/admin-graphql/2024-04/mutations/productCreate?example=Create+a+product+...

 

It seems you must have a variant for the product with those options before they are visible, they are created on the product, but in the UI you cannot see them until you have options with those values.

 

 

mutation CreateProductWithOptions($input: ProductInput!) {
  productCreate(input: $input) {
    userErrors {
      field
      message
    }
    product {
      id
      options {
        id
        name
        position
        values
        optionValues {
          id
          name
          hasVariants
        }
      }
      variants(first: 5) {
        nodes {
          id
          title
          selectedOptions {
            name
            value
          }
        }
      }
    }
  }
}

 

Tozell
Shopify Partner
11 0 4

First of all thank you for the response.  I have tested as outlined and requested a response of the option / values to indeed see the options I submit are there...   

 

I find that to be seriously annoying going around in circles looking at admin simply because the UI doesn't display all options that don't have variations , maybe ( and I doubt it ) they should change that to display such options greyed out to indicate their presence but disabled due to no variation. That would make way more sense.

jamalsoueidan
Shopify Partner
66 3 8

I agree