shopwareshopware6shopware6-api

How can we access store API endpoints from javascript in Shopware 6.5?


I see store-api-client.service.js was deleted in 6.5, however the docs are still referencing it: https://developer.shopware.com/docs/guides/plugins/plugins/storefront/fetching-data-with-javascript#call-the-store-api-from-the-storefront.

How should we access store API endpoints from javascript in 6.5?

Let's say a javascript plugin file that previously in 6.4 had:

        self._storeApiClient.get('/store-api/script/modigChatApp/initiate-chat', function (json) {
            const response = JSON.parse(json);

            if (!response.hasOwnProperty('subscriberToken')) {
                reject(response);
                return;
            }

            resolve(response.subscriberToken);
        });

How would this look like for 6.5?


Solution

  • I quote the deprecation notice in the changelog:

    The store-api proxy route was removed. Please use the store-api directly. If that is not possible use a custom controller, that calls the StoreApiRoute internally.
    The StoreApiClient class from storefront/src/service/store-api-client.service.js was also removed, as that class relied on the proxy route.

    That proxy route mentioned allowed you to use the store-api without explicit authorization, as the proxy used to authorize the request internally. This was deemed an undesirable workaround. If you want to use the store-api you'll have to create a proper integration, that will give you an access key. You then use the access key for authorization when you request the store-api.

    As the changelog mentions, if you don't want to handle authorization, you can also create a custom controller that calls a store-api endpoint internally, bypassing the authorization. See the original proxy controller for reference.