I am trying to add a product with an image via the WooCommerce REST API but getting this error:
Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: Error: #0 is an invalid image ID.
Despite many other threads similar, no one seems to have an actual answer to why this happens despite the same code in the example of the docs. The image I am trying to use is not already in the media library.
The code:
$woocommerce = new Client(
'https://www.example.co.uk',
'123456789',
'123456789',
[
'wp_api' => true,
'version' => 'wc/v3',
'sslverify' => false,
]
);
$data = array();
foreach ( $records->getRecords() as $record ) {
$data = [
'name' => $record['TITLE'],
'description' => $record['DESCRIPTION'],
'regular_price' => $record['PRICE'],
'quantity' => $record['QUANTITY'],
'images' => [
'src' => 'https://via.placeholder.com/350x150.png',
],
];
$woocommerce->post( 'products', $data );
}
I see nothing wrong. It’s setup in the same way as the example too: https://woocommerce.github.io/woocommerce-rest-api-docs/?php#create-a-product