I am trying to get Products using the Element API plugin. I set the 'elementType' to Commerce_Products
, CommerceProducts
, etc.., but the endpoint keeps returning:
Endpoint has an invalid elementType
This is my endpoint:
use craft\commerce\elements\Product as ProductsModel;
return [
'endpoints' => [
'api/search' => [
'elementType' => 'ProductsModel',
'paginate' => false,
'pretty' => true,
'criteria' => [
'limit' => 15,
'search' => (Craft::$app->request->getParam('keyName')) ? 'title:'.'*'.Craft::$app->request->getParam('keyName').'*' : ''
],
'transformer' => function(ProductsModel $product) {
return [
'title' => $product->title,
'url' => $product->url
];
},
],
]
];
How do I fix it?