# REST API (Shop) erweitern

**URL:** <https://forum.shopware.com/t/rest-api-shop-erweitern/57695>\
**Category:** Programmierung\
**Created:** [25. Januar 2019 um 14:41 UTC](https://forum.shopware.com/t/rest-api-shop-erweitern/57695 "2019-01-25T14:41:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_MikeB](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/_mikeb/32/7856_2.png) [@\_MikeB](https://forum.shopware.com/u/_MikeB)\
**Post date:** [25. Januar 2019 um 14:41 UTC](https://forum.shopware.com/t/rest-api-shop-erweitern/57695/1 "2019-01-25T14:41:12Z")

</div>

Hallo zusammen.

Ich versuche gerade die Shop API zu erweitern da ich viele Infos mit einem Request erhalten will. So sind neben den Shop Infos, Kategorien + Kindkategorien und deren Produkte enthalten. Funktioniert auch alles wunderbar soweit. Ich will den Output aber sehr schlank halten da ich nur wenige Informationen für Categorien und Produkte benötige. Leider schaffe ich es eben nicht nur ausgewählte Merkmale auszugeben. Es funktioniert immer nur mit dem gesamten Model. Hier mein Code:  
&nbsp;

```
    public function getList($offset = 0, $limit = 25, array $criteria = [], array $orderBy = [])
    {
        $this->checkPrivilege('read');

        $builder = $this->getRepository()->createQueryBuilder('shop')
            ->select('shop', 'category', 'children', 'article')
            ->leftJoin('shop.category', 'category')
            ->leftJoin('category.children', 'children')
            ->leftJoin('children.articles', 'article');

```

Das führt zu folgendem Output:

```
[0] => Array
        (
            [id] => 3
            [mainId] => 
            [categoryId] => 11
            [name] => Teststore
            [title] => Teststore
            [position] => 1
            [host] => testshop.de
            [basePath] => 
            [baseUrl] => 
            [hosts] => 
            [secure] => 
            [templateId] => 24
            [default] => 
            [active] => 1
            [customerScope] => 
            [category] => Array
                (
                    [sortingIds] => 
                    [hideSortings] => 
                    [facetIds] => 
                    [id] => 11
                    [parentId] => 1
                    [streamId] => 
                    [name] => Store
                    [position] => 1
                    [metaTitle] => 
                    [metaKeywords] => 
                    [metaDescription] => 
                    [cmsHeadline] => 
                    [cmsText] => 
                    [active] => 1
                    [template] => 
                    [productBoxLayout] => image
                    [blog] => 
                    [path] => 
                    [external] => 
                    [externalTarget] => 
                    [hideFilter] => 
                    [hideTop] => 
                    [changed] => 2019-01-15T14:57:36+0100
                    [added] => 2012-08-27T22:28:52+0200
                    [mediaId] => 
                    [children] => Array
                        (
                            [0] => Array
                                (
                                    [sortingIds] => 
                                    [hideSortings] => 
                                    [facetIds] => 
                                    [id] => 15
                                    [parentId] => 11
                                    [streamId] => 
                                    [name] => Kindkategorie
                                    [position] => 2
                                    [metaTitle] => 
                                    [metaKeywords] => 
                                    [metaDescription] => 
                                    [cmsHeadline] => 
                                    [cmsText] => 
                                    [active] => 1
                                    [template] => 
                                    [productBoxLayout] => 
                                    [blog] => 
                                    [path] => |11|
                                    [external] => 
                                    [externalTarget] => 
                                    [hideFilter] => 
                                    [hideTop] => 
                                    [changed] => 2019-01-14T12:47:23+0100
                                    [added] => 2019-01-14T12:47:23+0100
                                    [mediaId] => 
                                    [articles] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [id] => 4
                                                    [mainDetailId] => 4
                                                    [supplierId] => 1
                                                    [taxId] => 4
                                                    [priceGroupId] => 
                                                    [filterGroupId] => 
                                                    [configuratorSetId] => 
                                                    [name] => Mein Artikel
                                                    [description] => 
                                                    [descriptionLong] => Meine Artikelbeschreibung
                                                    [added] => 2019-01-15T00:00:00+0100
                                                    [active] => 1
                                                    [pseudoSales] => 0
                                                    [highlight] => 
                                                    [keywords] => 
                                                    [metaTitle] => 
                                                    [changed] => 2019-01-15T15:03:06+0100
                                                    [priceGroupActive] => 
                                                    [lastStock] => 
                                                    [crossBundleLook] => 0
                                                    [notification] => 
                                                    [template] => 
                                                    [mode] => 0
                                                    [availableFrom] => 
                                                    [availableTo] => 
                                                )

                                        )

                                )

                        )

                )

        )

```

&nbsp;

Wunschausgabe wäre aber folgende:

```
[0] => Array
        (
            [id] => 3
            [mainId] => 
            [categoryId] => 11
            [name] => Teststore
            [category] => Array
                (
                    [id] => 11
                    [parentId] => 1
                    [changed] => 2019-01-15T14:57:36+0100
                    [children] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 15
                                    [parentId] => 11
                                    [name] => Kindkategorie
                                    [position] => 2
                                    [active] => 1
                                    [changed] => 2019-01-14T12:47:23+0100
                                    [added] => 2019-01-14T12:47:23+0100
                                    [mediaId] => 
                                    [articles] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [id] => 4
                                                    [changed] => 2019-01-15T15:03:06+0100
                                                )

                                        )

                                )

                        )

                )

        )

```

So habe ich es probiert. Leider ohne Erfolg.

```
        $builder = $this->getRepository()->createQueryBuilder('shop')
            ->select('shop','category', 'children', 'article.id as article_id', 'article.changed as article_changed')
            ->leftJoin('shop.category', 'category')
            ->leftJoin('category.children', 'children')
            ->leftJoin('children.articles', 'article');

```

&nbsp;

Die Informationen werden zwar ausgeliefert aber sind nicht mehr im Fluss sondern am Ende angefügt. Was mache ich falsch?

&nbsp;

Beste Grüße  
Mike

---

<div class="post-metadata">

**Author:** ![langnickel](https://avatars.discourse-cdn.com/v4/letter/l/3ec8ea/32.png) [@langnickel](https://forum.shopware.com/u/langnickel)\
**Post date:** [25. Januar 2019 um 15:13 UTC](https://forum.shopware.com/t/rest-api-shop-erweitern/57695/2 "2019-01-25T15:13:13Z")

</div>

Du könntest vor dem ausliefern nur die felder die du benötigst raus plucken:

[http://php.net/manual/de/function.array-column.php](http://php.net/manual/de/function.array-column.php)

&nbsp;

---

<div class="post-metadata">

**Author:** ![MrMDeluxe](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@MrMDeluxe](https://forum.shopware.com/u/MrMDeluxe)\
**Post date:** [25. Januar 2019 um 16:22 UTC](https://forum.shopware.com/t/rest-api-shop-erweitern/57695/3 "2019-01-25T16:22:19Z")

</div>

Hallo Mike,

versuch es mal hiermit:

```
 ->select('shop','category', 'children')
 ->addSelect('partial article.{id,changed}')

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![\_MikeB](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/_mikeb/32/7856_2.png) [@\_MikeB](https://forum.shopware.com/u/_MikeB)\
**Post date:** [26. Januar 2019 um 10:47 UTC](https://forum.shopware.com/t/rest-api-shop-erweitern/57695/4 "2019-01-26T10:47:36Z")

</div>

@MrMDeluxe‍ Held! Funktioniert einwandfrei! Wünsch dir ein tolles Wochenende 😉
