I'm trying to add images to my products using CURL in PHP based on this: https://shopify.dev/api/admin-rest/2022-07/resources/product-image#post-products-product-id-images
This is what it should look like using CURL CLI but I'm trying to use it through PHP:
curl -d '{"image":{"src":"http://example.com/rails_logo.gif"}}' \
-X POST "https://your-development-store.myshopify.com/admin/api/2022-07/products/632910392/images.json" \
-H "X-Shopify-Access-Token: {access_token}" \
-H "Content-Type: application/json"
I've tried a number of different format but keep getting Cloudflare errors with the below format:
$ch = curl_init("https://STORENAME.myshopify.com/admin/api/2022-07/products/632910392/images.json");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Shopify-Access-Token: SECRETTOKEN"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_URL, "http://example.com/rails_logo.gif");
curl_setopt($ch, CURLOPT_INFILE, "http://example.com/rails_logo.gif");
curl_setopt($ch, CURLOPT_POSTFIELDS,'{"image":{"position":'1',"src":"http://example.com/rails_logo.gif"}}');
$responseTmp = curl_exec($ch);
I'm getting "BAD REQUEST" and "1020" errors from Cloudflare, I assume because something in my request isn't formatted correctly.
Would appreciate any advice.