Site icon Hip-Hop Website Design and Development

WooCommerce – Add product with picture through REST API

I’m making an attempt so as to add a product with a picture through the WooCommerce REST API however getting this error:

Deadly error: Uncaught
AutomatticWooCommerceHttpClientHttpClientException: Error: #0 is an
invalid picture ID.

Regardless of many different threads related, nobody appears to have an precise reply to why this occurs regardless of the identical code within the instance of the docs. The picture I’m making an attempt to make use of is just not already within the media library.

The code:

$woocommerce = new Shopper(
  'https://www.instance.co.uk',
  '123456789',
  '123456789',
  [
      'wp_api' => true,
      'version' => 'wc/v3',
      'sslverify' => false,
  ]
);

$knowledge = array();

foreach ( $records->getRecords() as $report ) {

  $knowledge = [
    'name' => $record['TITLE'],
    'description' => $report['DESCRIPTION'],
    'regular_price' => $report['PRICE'],
    'amount' => $report['QUANTITY'],
    'photos' => [
      'src' => 'https://via.placeholder.com/350x150.png',
    ],
  ];

  $woocommerce->submit( 'merchandise', $knowledge );
}

I see nothing incorrect. It’s setup in the identical means as the instance too:
https://woocommerce.github.io/woocommerce-rest-api-docs/?php#create-a-product