How do I get a specific product via Element API
?
Here's what i have so far
'api/product' => function() {
$productId = craft()->request->getRequiredQuery( 'productId' );
return [
'elementType' => Product::class,
// This provides Element API the fully qualified Element namespace + class.
'pretty' => true,
'criteria' => [
'relatedTo' => [ 'targetElement' => $categoryIds ],
],
'transformer' => function( Product $product ) {
return [
'title' => $product->title,
'url' => $product->url
];
}
];
}