Search code examples
apishopware6

API Logger for Shopware 6


In order to debug APIs with 3rd Parties, it is often helpful to see the API requests and responses. For Shopware 5 there was an extension for this purpose.

How to log API requests and responses in Shopware 6 ?


Solution

  • It depends which API scope you want to log requests for. There's store-api, api (commonly referred to as Admin-API) and storefront (not really an API in a narrower sense). If you want to log requests to just one of the scopes or log them to different file name patterns, then you could take a look at the RouteScopeListener on how to retrieve the scope from the request stack.

    You could then rebuild this listener in a plugin of yours and additionally inject the logger service. In the handler you then might check that the scope is one of those you want to log data for. Depending on that select the data from the request stack you want to log and where to log it.