Element-API migration - entries by category I am having trouble getting the related category passed thru to the entry api endpoint.

I cant use :

   $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Category);
        $criteria-&gt;id = $catId;
        $category = $criteria-&gt;first();


What is the equivalent in craft 3 api v2?

'api/v1/ship/category/&lt;catId:\d+&gt;.json' =&gt; function($catId) {
//old api craft 2
        $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Category);
        $criteria-&gt;id = $catId;
        $category = $criteria-&gt;first();

//api craft 3
        return [
            'elementType' =&gt; Entry::class,
            'elementsPerPage' =&gt; 30,
            'criteria' =&gt; [
                'criteria' =&gt; ['section' =&gt; 'ship'],
                'relatedTo' =&gt; ['targetElement' =&gt; $category],
            ],
            'transformer' =&gt; function(Entry $entry) {
                return [
                    'title' =&gt; $entry-&gt;title,
                    'id' =&gt; (int) $entry-&gt;id,
                    'slug' =&gt; $entry-&gt;slug,
                    'postDate' =&gt; $entry-&gt;postDate
                ];
            },
            'pretty' =&gt; true
        ];
    },
Solved it like this:

//categories
    'api/v1/ship/category/&lt;catId:\d+&gt;.json' =&gt; function($catId) {
        return [
            'elementType' =&gt; Category::class,
            'criteria'    =&gt; ['id'   =&gt; $catId],
            'paginate'    =&gt; false,
            'transformer' =&gt; function(Category $category) {
                $entries = Entry::find()-&gt;relatedTo($category)-&gt;all();

                $en=[];
                foreach($entries as $entry) {


                    //Final return
                    $en[]= [
                        "type" =&gt; "shipItem",
                        'sendtoseafarerhelp' =&gt; $entry-&gt;sendToSeafarerHelp,
                        'title' =&gt; $entry-&gt;title,
                        'url' =&gt; $entry-&gt;url,
                        'categoryTitle' =&gt; $entry-&gt;shipCategory[0]-&gt;title,
                        'categorySlug' =&gt; $entry-&gt;shipCategory[0]-&gt;slug,
                        'categoryUrl' =&gt; $entry-&gt;shipCategory[0]-&gt;uri,
                        'summary' =&gt; $entry-&gt;shipIntroText,
                        'descripton' =&gt; $entry-&gt;shipDescription,
                        'pdfs' =&gt; $pdfs,
                        'thumbs' =&gt; $thumbs,
                        'sponsors' =&gt; $sponsors                            
                    ];
                }

                return [
                    'title'   =&gt; $category-&gt;title,
                    'entries' =&gt; $en
                ];
            }
        ];
    },