Woocommerce-Version: 4.1.0
Ich versuche, ein Produkt mit Kategorien und Bildern über die API zu erstellen, aber ich erhalte diesen Fehler:
{“code”:”woocommerce_product_invalid_image_id”,”message”:”#0 ist eine ungültige Bild-ID.”,”data”:{“status”:400}}
Ich habe einige Antworten überprüft, aber ich verwende die Bilderweiterung in der URL, ich verwende nur die URL, nicht die ID, und ich verwende kein W3-Cache-Plugin. Hier ist das Bilder-Array der Anfrage:
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
)
)
Und das ist die vollständige Anfrage:
$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
]
] );