Rest API : Create product images

The unique image ID returned by calling the Create Product Image API is inconsistent with the product image unique ID returned by the Product Image Query API.

  • create product a image return image Id = “32239313780912”
post : admin/api/2022-07/products/7195763310768/images.json
body : {
    "image":{
      "src":"http:/xxxx/productImg/1A7R4H0R0/origin/main/TM/1656897692661.jpg"
    }
}
return : 
{
    "image": {
        "id": 32239313780912,
        "product_id": 7195763310768,
        "position": 1,
        "created_at": "2022-09-26T09:26:08+08:00",
        "updated_at": "2022-09-26T09:26:08+08:00",
        "alt": null,
        "width": 1200,
        "height": 1200,
        "src": "https://cdn.shopify.com/s/files/1/0617/0099/7296/products/tmz_1__1656897692661.jpg?v=1664155568",
        "variant_ids": [],
        "admin_graphql_api_id": "gid://shopify/ProductImage/32239313780912"
    }
}
  • Receive a list of all Product Images return image Id = “32239314305200”
get : admin/api/2022-07/products/7195763310768/images.json
return:
{
    "images": [
        {
            "id": 32239314305200,
            "product_id": 7195763310768,
            "position": 1,
            "created_at": "2022-09-26T09:26:25+08:00",
            "updated_at": "2022-09-26T09:26:25+08:00",
            "alt": "Burton Custom Freestyle 151 Burton",
            "width": 1200,
            "height": 1200,
            "src": "https://cdn.shopify.com/s/files/1/0617/0099/7296/products/Burton-Custom-Freestyle-151-Burton-1664155584.jpg?v=1664155585",
            "variant_ids": [],
            "admin_graphql_api_id": "gid://shopify/ProductImage/32239314305200"
        }
    ]
}

Hi Goelia,

When testing in a test store we’re finding that the image ID returned when adding a new image through a POST request to the endpoint at admin/api/2022-07/products/{productID}/images.json is the same as the one returned for that same filename when performing a GET request to that endpoint to get a list of images on the product.

In the example you provided the ‘src’ and ‘admin_graphql_api_id’ fields are different between the POST and GET requests which helps to show that those two image ID’s are referring to different assets.

The timestamps in those two examples are only 17 seconds apart so the main thing that comes to mind is some potential processing delays before the new image appears in the list of images attached to the product, so trying the GET request a little later might be a good thing to try.

If you’re still having trouble please submit an authenticated support request through [the Support Centre] to enable further investigation.

Thanks and hope you have a great day,