How To Replace CJ Image URL To Shopify URL In Product Description

How To Replace CJ Image URL To Shopify URL In Product Description

AndyChou
Shopify Partner
11 0 0
Hi Shopify Team,
 
When I was creating a product, there were images in my product description. The current image URLs are the image urls of CJ. I hope to upload the images to Shopify and obtain the image URL, and replace the image URL of CJ with the image Url of Shopify. How can I do this?
Which api does it need to use?
 
Best.
 
Thanks.
Replies 2 (2)

Liam
Community Manager
3108 340 871

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:

  1. Create a new product or locate the ID of the existing product you want to add images to.

  2. 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"
  }
}
  1. Shopify will upload the image from the source URL you provided to their servers. Once the image is uploaded, the response will include the new image object with its ID and the new URL on Shopify's servers. You can use this URL to replace the old one in your product description.

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

AndyChou
Shopify Partner
11 0 0

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?