Get a specific product with Element API, Commerce and Craft 2 How do I get a specific product via Element API?

Here's what i have so far

'api/product' =&gt; function() {
    $productId = craft()-&gt;request-&gt;getRequiredQuery( 'productId' );

    return [
        'elementType' =&gt; Product::class,
        // This provides Element API the fully qualified Element namespace + class.
        'pretty'      =&gt; true,
        'criteria'    =&gt; [
            'relatedTo' =&gt; [ 'targetElement' =&gt; $categoryIds ],
        ],
        'transformer' =&gt; function( Product $product ) {
            return [
                'title' =&gt; $product-&gt;title,
                'url'   =&gt; $product-&gt;url
            ];
        }

    ];
}
If you want to get a specific product and it's variants by the productId you could simply do:

'api/product/&lt;productId&gt;' =&gt; function( $productId ) {
    return [
        'elementType' =&gt; Product::class,
        'criteria'    =&gt; [
            'id' =&gt; $productId
        ],
        'pretty'      =&gt; true,
        'transformer' =&gt; function( Product $product ) {
            foreach ( $product-&gt;getVariants() as $variant ) {
                $variants = [
                    'title'         =&gt; $variant-&gt;title,
                    'description'   =&gt; $variant-&gt;description,
                    'productId'     =&gt; (int) $variant-&gt;productId,
                    'purchasableId' =&gt; (int) $variant-&gt;purchasableId,
                    'status'        =&gt; $variant-&gt;status,
                    'type'          =&gt; $product-&gt;type-&gt;name,
                    'url'           =&gt; $product-&gt;url,
                ];
            }

            return $variants;
        },
    ];
},


you are able to get the product then via yourshop.domain/product/1234