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.

Upload Images using GraphQl

Upload Images using GraphQl

kissa14
Shopify Partner
9 0 1

Hi,

To create new products, I have to use the productSet API, but I must first upload the images via FileCreate and retrieve the media IDs.

the problem when I create all the images of the new products, I cannot map between the data 'fileCreate' returned by API, and the images ID in my ERP.

My question, does Shopify respect the order of media created in the API response?

Exemple: is the image indexed 3 in the table sent in the API is that of the image indexed 3 in the DATA response table?

 

Thank you

Replies 3 (3)

Kyle_liu
Shopify Partner
359 46 60

Hi @kissa14 

 

I'm not sure if the order is followed, but you can try using the id returned in the fileCreate API to call productSet and fill in the mediaIds

 

{
  "synchronous": true,
  "input": {
    "title": "T-product-3--2",
    "descriptionHtml": "<p>asf12121212asdfa儿童瓦尔塔玩儿森岛帆高阿萨法阿萨法ertwetwrtwtwertwtwrtwet66465`13121212121</p>\n",
    "productType": "xq",
    "handle": "t-product-3--2",
    "status": "ACTIVE",
    "tags": "xq1",
    "productOptions": [
      {
        "name": "size",
        "values": [
          {
            "name": "m"
          },
          {
            "name": "s"
          },
          {
            "name": "l"
          }
        ]
      },
      {
        "name": "color",
        "values": [
          {
            "name": "black"
          },
          {
            "name": "red"
          },
          {
            "name": "pink"
          }
        ]
      }
    ],
    "variants": [
      {
        "price": "13.32",
        "sku": "39549861654646-1",
        "optionValues": [
          {
            "optionName": "size",
            "name": "l"
          },
          {
            "optionName": "color",
            "name": "pink"
          }
        ]
      },
      {
        "price": "13.11",
        "sku": "39549861654646-1",
        "optionValues": [
          {
            "optionName": "size",
            "name": "l"
          },
          {
            "optionName": "color",
            "name": "red"
          }
        ]
      },
      {
        "price": "13.11",
        "sku": "39549861654646-1",
        "optionValues": [
          {
            "optionName": "size",
            "name": "l"
          },
          {
            "optionName": "color",
            "name": "black"
          }
        ]
      },
      {
        "price": "11.23",
        "sku": "39549861654646-1",
        "optionValues": [
          {
            "optionName": "size",
            "name": "s"
          },
          {
            "optionName": "color",
            "name": "black"
          }
        ]
      },
      {
        "price": "11.23",
        "sku": "39549861654646-1",
        "optionValues": [
          {
            "optionName": "size",
            "name": "s"
          },
          {
            "optionName": "color",
            "name": "pink"
          }
        ]
      },
      {
        "price": "11.11",
        "sku": "39549861654646-1",
        "optionValues": [
          {
            "optionName": "size",
            "name": "s"
          },
          {
            "optionName": "color",
            "name": "red"
          }
        ]
      },
      {
        "price": "11.11",
        "sku": "39549861654646-1",
        "optionValues": [
          {
            "optionName": "size",
            "name": "m"
          },
          {
            "optionName": "color",
            "name": "pink"
          }
        ]
      },
      {
        "price": "11.11",
        "sku": "39549861654646-1",
        "optionValues": [
          {
            "optionName": "size",
            "name": "m"
          },
          {
            "optionName": "color",
            "name": "red"
          }
        ]
      },
      {
        "price": "11.2",
        "sku": "39549861654646-1",
        "optionValues": [
          {
            "optionName": "size",
            "name": "m"
          },
          {
            "optionName": "color",
            "name": "black"
          }
        ]
      }
    ],
  "mediaIds": [
   "gid://shopify/MediaImage/39306318807315"
  ]
  }
}

 

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me Email Me Buy Me A Coffee
kissa14
Shopify Partner
9 0 1

hi @Kyle_liu 

Thank you for your response, but in my case I work with bulk products.

AsafGitai
Shopify Staff
109 16 45

Hi @kissa14 

I have passed this along to the relevant team and they will get back to you