# Admin API: Relationships im Response JSON erweitern

**URL:** <https://forum.shopware.com/t/admin-api-relationships-im-response-json-erweitern/98934>\
**Category:** Programmierung\
**Created:** [13. März 2023 um 17:45 UTC](https://forum.shopware.com/t/admin-api-relationships-im-response-json-erweitern/98934 "2023-03-13T17:45:13Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gheiner](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Gheiner](https://forum.shopware.com/u/Gheiner)\
**Post date:** [13. März 2023 um 17:45 UTC](https://forum.shopware.com/t/admin-api-relationships-im-response-json-erweitern/98934/1 "2023-03-13T17:45:13Z")

</div>

Hi,  
wie kann man den Inhalt der „relationships“ im JSON Response erweitern, so dass deren Inhalt direkt im Response mit angezeigt wird?

Beispiel:  
mit GET /api/order/{id}

Befinden sich die relevanten Infos alle in den relationships (Lieferadresse, Rechnungsadresse etc.)

Ich möchte aber nicht für jede Order XX Endpunkte ansprechen, sondern nur einen, um an die relevanten Daten zu kommen.

Mit dem Parameter \_response=detail bekomme ich auch nicht mehr Informationen.

Wie komme ich an ein JSON, das alle relevanten Infos inkl. Liefer/Rechnungsadresse enthält?

---

<div class="post-metadata">

**Author:** ![AlexGalax](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/alexgalax/32/9925_2.png) [@AlexGalax](https://forum.shopware.com/u/AlexGalax)\
**Post date:** [14. März 2023 um 08:09 UTC](https://forum.shopware.com/t/admin-api-relationships-im-response-json-erweitern/98934/2 "2023-03-14T08:09:28Z")

</div>

`GET /api/orders/{id}` ist der korrekt Endpunkt (nicht `/order`).  
Da ist alles drin.

> **[REST API - Examples using the order resource](https://developers.shopware.com/developers-guide/rest-api/examples/order/#example-2-loading-a-specific-order)**
>
> REST API - Examples using the order resource

---

<div class="post-metadata">

**Author:** ![Gheiner](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Gheiner](https://forum.shopware.com/u/Gheiner)\
**Post date:** [14. März 2023 um 09:07 UTC](https://forum.shopware.com/t/admin-api-relationships-im-response-json-erweitern/98934/3 "2023-03-14T09:07:14Z")

</div>

@AlexGalax Wir sind hier im Shopware 6 Forum.

Hat denn niemand eine Lösung für das Problem?  
Es kann doch nicht sein, dass ich 4 Endpunkte ansprechen muss, nur um an die Adressen zu kommen??

Ich bin über jeden Tipp dankbar!

---

<div class="post-metadata">

**Author:** ![AlexGalax](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/alexgalax/32/9925_2.png) [@AlexGalax](https://forum.shopware.com/u/AlexGalax)\
**Post date:** [14. März 2023 um 09:46 UTC](https://forum.shopware.com/t/admin-api-relationships-im-response-json-erweitern/98934/4 "2023-03-14T09:46:01Z")

</div>

> [@Gheiner](#):
>
> Wir sind hier im Shopware 6 Forum.

Sorry, mein Fehler.

In Shopware 6 kannst du über die Search API die Associations mit angeben.

`POST /api/search/order`

> **[Search Criteria | Shopware Documentation](https://developer.shopware.com/docs/guides/integrations-api/general-concepts/search-criteria.html)**
>
> Documentation for Shopware developers

So sieht z.B. der Request-Body von Shopware aus:

```js
{
	"associations": {
		"addresses": {
			"associations": {
				"country": {
					"total-count-mode": 1
				},
				"countryState": {
					"total-count-mode": 1
				}
			},
			"total-count-mode": 1
		},
		"currency": {
			"total-count-mode": 1
		},
		"deliveries": {
			"associations": {
				"shippingMethod": {
					"total-count-mode": 1
				},
				"shippingOrderAddress": {
					"total-count-mode": 1
				}
			},
			"sort": [
				{
					"field": "shippingCosts.unitPrice",
					"naturalSorting": false,
					"order": "DESC"
				}
			],
			"total-count-mode": 1
		},
		"documents": {
			"associations": {
				"documentType": {
					"total-count-mode": 1
				}
			},
			"total-count-mode": 1
		},
		"language": {
			"total-count-mode": 1
		},
		"lineItems": {
			"associations": {
				"children": {
					"sort": [
						{
							"field": "label",
							"naturalSorting": true,
							"order": "ASC"
						}
					],
					"total-count-mode": 1
				},
				"product": {
					"total-count-mode": 1
				}
			},
			"filter": [
				{
					"field": "parentId",
					"type": "equals",
					"value": null
				}
			],
			"sort": [
				{
					"field": "position",
					"naturalSorting": false,
					"order": "ASC"
				}
			],
			"total-count-mode": 1
		},
		"orderCustomer": {
			"total-count-mode": 1
		},
		"salesChannel": {
			"total-count-mode": 1
		},
		"tags": {
			"total-count-mode": 1
		},
		"transactions": {
			"associations": {
				"paymentMethod": {
					"total-count-mode": 1
				}
			},
			"sort": [
				{
					"field": "createdAt",
					"naturalSorting": false,
					"order": "ASC"
				}
			],
			"total-count-mode": 1
		}
	},
	"ids": "f956993c77894ce28da1daedc60c7626",
	"limit": 25,
	"page": 1,
	"total-count-mode": 1
}

```

---

<div class="post-metadata">

**Author:** ![Gheiner](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Gheiner](https://forum.shopware.com/u/Gheiner)\
**Post date:** [14. März 2023 um 10:07 UTC](https://forum.shopware.com/t/admin-api-relationships-im-response-json-erweitern/98934/5 "2023-03-14T10:07:11Z")

</div>

@AlexGalax Hey, danke dir. Damit bekomme ich schon mehr informationen.  
Allerdings werden mir mit

```auto
{
	"associations": {
		"addresses": {
			"associations": {
				"country": {
					"total-count-mode": 1
				},
				"countryState": {
					"total-count-mode": 1
				}
			},
			"total-count-mode": 1
		},

```

…trotzdem keine Adressen angezeigt.  
Ich habe keine Infos gefunden, wie man „sämtliche“ Elemente innerhalb von „addresses“ anzeigen kann.  
Was muss man „associations“ übergeben, um alles innerhalb von „addresses“ anzuzeigen?

---

<div class="post-metadata">

**Author:** ![AlexGalax](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/alexgalax/32/9925_2.png) [@AlexGalax](https://forum.shopware.com/u/AlexGalax)\
**Post date:** [14. März 2023 um 10:18 UTC](https://forum.shopware.com/t/admin-api-relationships-im-response-json-erweitern/98934/6 "2023-03-14T10:18:42Z")

</div>

Vielleicht weil Liefer- & Rechnungsadresse gleich sind. Füg mal noch die Assosiation für `billingAddress` hinzu.

---

<div class="post-metadata">

**Author:** ![Gheiner](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Gheiner](https://forum.shopware.com/u/Gheiner)\
**Post date:** [14. März 2023 um 10:22 UTC](https://forum.shopware.com/t/admin-api-relationships-im-response-json-erweitern/98934/7 "2023-03-14T10:22:12Z")

</div>

@AlexGalax  
dann bekomme ich innerhalb von billingAddress nur die ID der billingAddress, siehe unten. Aber ich will ja die Adresse sehen und nicht die ID.  
Vielleicht ist das in SW6 doch nicht möglich, alles anzuzeigen? Und ich muss mit der ID immer die entsprechenden Endpunkte nacheinander abklappern?

```auto
	"billingAddress" : 
				{
					"data" : 
					{
						"id" : "78d48538620444e28922f7c0fda65ccd",
						"type" : "order_address"
					},
					"links" : 
					{
						"related" : "https://abc.de/api/order/a6b12e295fd8477582533d7de596e1a9/billing-address"
					}
				},

```

---

<div class="post-metadata">

**Author:** ![AlexGalax](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/alexgalax/32/9925_2.png) [@AlexGalax](https://forum.shopware.com/u/AlexGalax)\
**Post date:** [14. März 2023 um 11:43 UTC](https://forum.shopware.com/t/admin-api-relationships-im-response-json-erweitern/98934/8 "2023-03-14T11:43:15Z")

</div>

Poste bitte mal den Request-Body

---

<div class="post-metadata">

**Author:** ![Gheiner](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Gheiner](https://forum.shopware.com/u/Gheiner)\
**Post date:** [14. März 2023 um 12:28 UTC](https://forum.shopware.com/t/admin-api-relationships-im-response-json-erweitern/98934/9 "2023-03-14T12:28:16Z")

</div>

Hier die einfachste Version zum Anzeigen der Adressen und Line-Items:

```auto
{
	"associations" : 
	{
		"billingAddress" : {},
		"deliveries" : {},
		"lineItems" : {}
	}
}

```

---

<div class="post-metadata">

**Author:** ![Gheiner](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Gheiner](https://forum.shopware.com/u/Gheiner)\
**Post date:** [14. März 2023 um 12:38 UTC](https://forum.shopware.com/t/admin-api-relationships-im-response-json-erweitern/98934/10 "2023-03-14T12:38:34Z")

</div>

Hab in einem anderen Post die Lösung gefunden.  
Es kann folgende Payload verwendet werden, um an die Details zu gelangen:

```auto
{
    "associations": {
        "addresses": {
            "associations": {
                "country": []
            }
        },
        "transactions": {
            "associations": {
                "stateMachineState": [],
                "paymentMethod": []
            }
        },
        "salesChannel": {
            "associations": {}
        },
        "deliveries": {
            "associations": {
                "shippingOrderAddress": [],
                "shippingMethod": {
                    "associations": {
                        "deliveryTime": []
                    }
                }
            }
        },
        "orderCustomer": {},
        "lineItems": {
            "associations": {
                "product": []
            }
        }
    },
    "includes": {
        "order": [
            "id",
            "orderNumber",
            "createdAt",
            "lineItems",
            "billingAddressId",
            "salesChannelId",
            "addresses",
            "deliveries",
            "salesChannelId",
            "salesChannel",
            "stateMachineState",
            "transactions",
            "orderCustomer",
            "shippingTotal"
        ],
        "state_machine_state": [
            "id",
            "technicalName"
        ],
        "sales_channel": [
            "id",
            "name"
        ],
        "payment_method": [
            "id",
            "name",
            "formattedHandlerIdentifier"
        ],
        "shipping_method": [
            "id",
            "name",
            "deliveryTimeId",
            "deliveryTime"
        ],
        "order_transaction": [
            "id",
            "stateMachineState",
            "paymentMethodId",
            "paymentMethod"
        ],
        "order_address": [
            "id",
            "firstName",
            "lastName",
            "street",
            "zipcode",
            "city",
            "company",
            "department",
            "countryId",
            "country",
            "phoneNumber"
        ],
        "country": [
            "iso"
        ],
        "order_customer": [
            "email"
        ],
        "order_delivery": [
            "id",
            "shippingOrderAddressId",
            "shippingMethodId",
            "shippingMethod"
        ],
        "order_line_item": [
            "id",
            "position",
            "quantity",
            "unitPrice",
            "productId",
            "product",
            "payload"
        ],
        "product": [
            "productNumber",
            "name"
        ]
    }
}

```
