Search code examples
phpjsonapishopwareshopware6

Shopware6 document API request


I am currently trying to get documents from my shopware instance through the api (shopware.emakers.eu/api/document), I need all the documents (all types) and for each single document I need the order informations related to it.

So, here's the body of my POST request that I am simulating on Postman :

{
    "associations": {
        "transactions": {
            "associations": {
                "order": {
                    "associations": {}
                }
            }
        }
    }
}

I expected this to work but for a reason that I did not understand yet, I am getting an error response that asks me to mention an orderId, documentTypeId, fileType, config, deepLinkCode. It seems that it's trying to create a new document.

Maybe I am using the wrong api endpoint ? But this endpoint works if I only make a GET request. And I don't know which endpoint I can use in case of this is not the correct one.

Any clue ?


Solution

  • Sounds like it is indeed the wrong endpoint. POST /api/document would only be correct to create a new document record.

    There are two ways to fetch data of one or more records.

    1. Use GET /api/document/{id}?associations[order][] if you have the id of a specific document record. Since it requires the GET method you must provide the associations as query params.

    2. Use the endpoint POST /api/search/document to search for any documents and add the association in the request body.

    {
        "associations": {
            "order": {}
        }
    }