Focusing on managing products, variants, and collections through the API.
Hi AndyChou,
I don't think there's one specific API that will take your existing image URLs, upload a image and replace the existing image URLs with the Shopify one - but you should be able to do this in separate steps.
To upload images to a product in Shopify and get their URLs, you can use the ProductImage
resource of the Shopify Admin API. Here is a general step-by-step process:
Create a new product or locate the ID of the existing product you want to add images to.
Use the POST /admin/api/2023-10/products/{product_id}/images.json
endpoint to upload a new image. In the request body, you need to include the src
field which should contain the source URL of the image you want to upload. Here is an example:
{
"image": {
"src": "http://example.com/rails_logo.gif"
}
}
Here is an example of a response from Shopify:
{
"image": {
"id": 8597307020803,
"product_id": 632910392,
"src": "https://cdn.shopify.com/s/files/1/0006/9093/3842/products/test-product.jpg?v=1628102099",
"created_at": "2023-03-14T19:55:23-04:00",
"updated_at": "2023-03-14T19:55:23-04:00",
"position": 1,
"alt": null,
"width": 123,
"height": 456
}
}
Now that you have a Shopify URL you can replace this with the "old" URL in your product descriptions.
Hope this helps!
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Thanks Liam.
I have tried this before, and the uploaded image will also display the images in the shopify product images, which is not what I want. Is there any way I can upload an image without displaying it in the shopify product image?