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.

How to add images to productVariant in productCreate

Solved

How to add images to productVariant in productCreate

Serhii_Khr
Shopify Partner
1 0 0
`
  mutation populateProduct($input: ProductInput!) {
    productCreate(input: $input) {
      userErrors {
        field
        message
      }
      product {
        title
        descriptionHtml
        seo {
          title
          description
        }
        options {
          values
        }
        images {
          edges {
            node {
              src
            }
          }
        }
        metafields(first: 1) {
          edges {
            node {
              namespace
              type
              key
              value
            }
          }
        }
        variants(first: 1) {
          edges {
            node {
              price
              selectedOptions {
                value
              }
              image {
                url
              }
            }
          }
        }
      }
    }
  }
`

INPUT:

 {
    "title": "OXIDOM-100 (ОКСИДОМ-100) - Натуральное льняное масло-воск для дерева (масло льна с воском).",
    "descriptionHtml": "<p style=\"text-align: justify;\">Натуральное <strong>льняное масло с добавлением пчелиного воска&nbsp;Oxidom-100 </strong><b>(ОксиДом-</b><b>100)</b> - готовая пропитка для дерева наружного и внутреннего применения и изделий из древесины, содержит незначительное количество экстракта хвойных пород для поддержания в жидком состоянии продукта. Oxidom-100 (ОксиДом-100) отлично подходит для декорирования и защиты всех пород древесины, хорошо впитывается и имеет антисептические свойства, что способствует защите древесины от биопоражения. В смеси льняного масла с воском получаем дополнительный слой защиты дерева, который образует пленка на поверхности поле высыхания, а так изделие можно натирать до блеска.</p>",
    "seo": {
      "title": "seo title",
      "description": "seo description"
    },
    "options": ["Колір", "Фасування", "Блиск"],
    "images": [
      {
        "src": "https://oxidom.com/upload/iblock/c98/oxidom-100_1L.webp?1583074032"
      },
      {
        "src": "https://oxidom.com/upload/iblock/e92/oxidom-100_3L.png"
      },
      {
        "src": "https://oxidom.com/upload/iblock/64a/oxidom-100_10L.png"
      }
    ],
    "variants": [
      {
        "price": "257",
        "options": ["безбарвний", "1 л.", "матовий"],
        "image": {
          "url": "https://oxidom.com/upload/iblock/c98/oxidom-100_1L.webp?1583074032"
        }
      },
      {
        "price": "692",
        "options": ["безбарвний", "3 л.", "матовий"],
        "image": {
          "url": "https://oxidom.com/upload/iblock/e92/oxidom-100_3L.png"
        }
      },
      {
        "price": "2161",
        "options": ["безбарвний", "10 л.", "матовий"],
        "image": {
          "url": "https://oxidom.com/upload/iblock/64a/oxidom-100_10L.png"
        }
      }
    ],
    "metafields": [
      {
        "namespace": "productProperties",
        "type": "single_line_text_field",
        "key": "колір",
        "value": "Білий, після висихання прозорий"
      },
      {
        "namespace": "productProperties",
        "type": "single_line_text_field",
        "key": "код товару (артикул)",
        "value": "31888"
      },
      {
        "namespace": "productProperties",
        "type": "single_line_text_field",
        "key": "час висихання",
        "value": "2-3 години"
      },
      {
        "namespace": "productProperties",
        "type": "single_line_text_field",
        "key": "висихання від пилу",
        "value": "12 годин"
      },
      {
        "namespace": "productProperties",
        "type": "single_line_text_field",
        "key": "витрата",
        "value": "10-14 м²/л."
      },
      {
        "namespace": "productProperties",
        "type": "multi_line_text_field",
        "key": "з УФ-фільтром\nзносостійкість",
        "value": "10-14 м²/л."
      }
    ]
  }

ERROR:

Serhii_Khr_1-1675264916680.png

 

 

Accepted Solution (1)

garyrgilbert
Shopify Partner
433 41 191

This is an accepted solution.

Hi There,

 

In your productvariant input try "imageSrc" instead of "image"

 

https://shopify.dev/api/admin-graphql/2023-01/input-objects/ProductVariantInput

 

Cheers,

 

Gary

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution

View solution in original post

Reply 1 (1)

garyrgilbert
Shopify Partner
433 41 191

This is an accepted solution.

Hi There,

 

In your productvariant input try "imageSrc" instead of "image"

 

https://shopify.dev/api/admin-graphql/2023-01/input-objects/ProductVariantInput

 

Cheers,

 

Gary

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution