## wc_get_products() return empty object

Question

I’m trying to get all the products that exists in database, but my code return empty objects.
just for the sake of testing, first I’m trying to get only 10 products,
here is my code

add_action('rest_api_init', 'getProducts');
function getProducts()
{
register_rest_route('products/v1/', 'allproducts', array(
$products = wc_get_products(array( 'limit' => 10 )); return$products;