FROM CACHE - en_header

cannot create product with image

jiang_
New Member
1 0 0

Hi,
I have i problem with creating a product with its images using the API 2021-01.
The images array is sometimes empty in the returned result,
Here's my schema tha i send to "https://shopname.myshopify.com/admin/api/2021-01/products.json" :

79918CBB-3A2F-4655-9E2D-F3E2C51837B1.png

return empty images

C395C09F-6DB6-4984-8561-734548012A4F.png

The product is added successfully but without images or image

Replies 4 (4)
Greg_Kujawa
Shopify Partner
1023 84 266

Using the REST API, I believe you need to first create the new image and then create the new product/variant and assign the image to the new record. With the GraphQL API you can likely create everything all in one shot. Using the REST API, not so much...

HMM100
Tourist
6 0 0

I am a beginner, can you give me an example of code, in order to understand more easily

HMM100
Tourist
6 0 0

can you tell me how to use graphQL create product with images in variant,Can you give me a code example

DenisSabolotni
Shopify Partner
12 1 15

Hey there,

Response to:

 


@HMM100 wrote:

can you tell me how to use graphQL create product with images in variant,Can you give me a code example


 

this is what I've learned when working with the GraphQL API. It is possible to create a product with images. I will also add the information on how to create a product with an image and variants that also have those images assigned because it is related.

 

If you don't know how to use the GraphQL API you can checkout the following resources: 

 

  1.  You need to define a GraphQL query

 

 

mutation productCreate($input:ProductInput!) {
  productCreate(input: $input) {
    product {
      title
    }
  }
}

 

 

Notice: You don't have to mention the image attribute in the query, because what you define with it, is the response the request delivers and not the request itself...

 

     2. Create the object you will send to the GraphQL API

 

 

 

{
  "title": "Test product",
  "options": [
    "NewOption",
  ],
  "images": [
    {
      "src": "https://cdn.shopify.com/s/files/1/0609/3242/3910/products/download_0e944bb8-3b3e-499d-899d-95e1eb03fa42.jpg?v=1636291618"
    },
    {
    "src": "https://cdn.shopify.com/s/files/1/0609/3242/3910/products/download.jpg?v=1636291617"
    }
  ]
  "variants": [
    {
      "price": 20,
      "sku": "SKU_01",
      "barcode": "1",
      "imageSrc": "https://cdn.shopify.com/s/files/1/1234/1234/1234/products/picture1.jpg?v=12345678",
      "options": [
        "Option value",
      ],
      "title": "title1",
      "position": 1
    },
    {
      "price": 20,
      "sku": "SKU_02",
      "barcode": "2",
      "imageSrc": "https://cdn.shopify.com/s/files/1/1234/1234/1234/products/picture2.jpg?v=1636291617",
      "options": [
        "Other option value"
      ],
      "title": "title2",
      "position": 2
    }
  ]
}

 

 

 

That's it. Here are some other resources that may help you:

 

I hope I could help!