Upload Images using GraphQl

Upload Images using GraphQl

kissa14
Shopify Partner
4 0 0

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
89 14 15

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 on (liushuaicc@shinetechsoftware.com)
kissa14
Shopify Partner
4 0 0

hi @Kyle_liu 

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

AsafGitai
Shopify Staff
48 8 11

Hi @kissa14 

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