Shopware 6 - store-api list orders with associated documents

38 Views Asked by At

Using Shopware 6 store-api, I want a list of orders with associated documents. I submit a POST the store-api/order endpoint with this body:

{
    "includes": {
        "order": [
            "orderNumber",
            "documents"
        ]
    },
    "associations": {
        "documents": []
    }
}

However, the response just shows empty arrays for the documents.

{
    "apiAlias": "order-route-response-struct",
    "orders": {
        "elements": [
            {
                "orderNumber": "SW1001",
                "documents": [],
                "apiAlias": "order"
            },
            {
                "orderNumber": "SW1002",
                "documents": [],
                "apiAlias": "order"
            }
        ],
        "aggregations": [],
        "page": 1,
        "limit": 100,
        "entity": "order",
        "total": 2,
        "states": [],
        "apiAlias": "dal_entity_search_result"
    },
    "paymentChangeable": []
}

In Shopware Admin I can verify that both orders do have associated invoices.

How can I enforce the response to contain the information for the associated orders?

1

There are 1 best solutions below

0
Benny On

For a document to be included in the response to the store-api/order endpoint,

  1. the document must have been sent to the customer and
  2. the document type settings in admin must specify 'Display document in "My Account"' (see screenshot).

How to configure documents in Admin

Note that the latter (2.) has to take place before (!) a document is created, the setting will have no effect for existing documents.