HTTP response from Admin REST API on wrong content-type for product image

Highlighted
New Member
1 0 0
Hi,
 
We used to send our product with a base64 encoded image,  but we recently changed this to instead send the CloudFront CDN url.  This change caused an issue.
 
We were sending products to the API, now with a url instead of the base64, and we got `201 Created` back. But all the products would appear without any images. We found out that the issue seemed to be with the content-type of the image being uploaded.  All the images had the content-type`application/octet-stream`, which is the default AWS S3 content-type. We fixed this on our side by setting the proper content-type on the image when we upload it to S3, and voilà: issue solved.
 
But shouldn’t Shopify API return a content-type validation error on this call, instead of the `201 Created`?
 
Example:
 
POST /admin/products.json
{
  “product”: {
    “title”: “Burton Custom Freestyle 151”,
    “body_html”: “<strong>Good snowboard!</strong>”,
    “vendor”: “Burton”,
    “product_type”: “Snowboard”,
    “tags”: [
      “Barnes & Noble”,
    ],
    "images":[{
      "src":"https://d1vk7rtgnzzicy.cloudfront.net/5e452fe2abdbde000c494f6e/iphonexr-2.png"
    }],
  }
}
 
Example response (notice missing image):
{
  “product”: {
    “title”: “Burton Custom Freestyle 151”,
    “body_html”: “<strong>Good snowboard!</strong>”,
    “vendor”: “Burton”,
    “product_type”: “Snowboard”,
    “tags”: [
      “Barnes & Noble”,
    ],
   "images":[],
   ...
  }
}
0 Likes
Shopify Staff
Shopify Staff
607 82 89

Hey @lazreg87,

 

I guess since images aren't required, the product is created anyway and a 201 is returned.

 

A content validation error could be helpful - Out of curiosity, have you tried sending an invalid image to /admin/api/2020-01/products/#{product_id}/images.json?

0 Likes