'Woocommerce Rest API: woocommerce_product_invalid_image_id
Woocommerce version: 4.1.0
I am trying to create a product with categories and images via the API but I get this error :
{"code":"woocommerce_product_invalid_image_id","message":"#0 is an invalid image ID.","data":{"status":400}}
I have checked some answers but I use image extension in the url, I use only the url not the id and I am not using W3 Cache plugin. Here is the images array of the request:
Array
(
[0] => Array
(
[0] => Array
(
[0] => https://www.domainzzz.com/wp-content/uploads/2019/05/MB-150x150.jpg
[1] => 150
[2] => 150
[3] => 1
)
[position] => 0
)
[1] => Array
(
[0] => https://www.domainzzz.com/wp-content/uploads/2020/04/MG_2072-copy.png
[position] => 1
)
[2] => Array
(
[0] => https://www.domainzzz.com/wp-content/uploads/2020/04/MG_2071-copy.png
[position] => 2
)
)
And this is the full request:
$api_response = wp_remote_post( 'https://newdomain.com/wp-json/wc/v2/products', [
'headers' => [
'Authorization' => 'Basic ' . base64_encode( 'ck_306dd02a04f81cc33df:cs_4b3c7be0a0' )
],
'body' => [
'name' => $product->get_name(), // product title
'slug' => $product->get_slug(),
'sku' => $product->get_sku(),
'description' => $product->get_description(),
'status' => get_post_status($post_id), // product status, default: publish
'categories' => $cat_ids,
'images' => $images,
'regular_price' => $product->get_price() // product price
// more params http://woocommerce.github.io/woocommerce-rest-api-docs/?shell#product-properties
]
] );
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|