The Internet of things is offering immense opportunities. APIs are tightly linked with IoT because they allow you to securely expose the shop platform to connect devices to customers, go-to-market channels and other applications in your IT infrastructure. With Shopware 6, the software was put on a completely new basis where the API-first approach is consistently pursued. Compared to the previous version, this has the advantage that all shop functionalities can also be controlled via the API.
This Blogpost gives you insights into the API of Shopware 6. The questions we like to answer are: How does the API work? And what can you do with it?
First of all - the API doesn’t mean there is one to rule them all. So there are three Rest APIs with their own purpose. All of them rely on the HTTP protocol.
- Admin API
- Sync API
- Sales Channel API
What is the purpose of the Admin API?
The main purpose of the Admin API is to manage your shop. That means CRUD operation for all entities as well as administering asset uploading. The Admin API is consistently used by the new Administration, which is based on Vue.js. You can use all settings and functionality of the administration via the Admin API. This makes it possible to create custom interfaces for administrative activities, for example, a view for open orders that have to be shipped.
Your custom entities will get an API endpoint automatically. This is possible due to the tight integration with our DAL (data abstraction layer) which provides CRUD operations for custom entities without creating new controllers.
We chose OAuth as the authentication method for the Admin API since it’s well known and widely used.
Besides typical JSON formatted responses, we support JSON: API. It is a specification for building standardized APIs. Standards like this give you the benefit of not having to argue with your colleagues about how to respond to errors, how the pagination looks like or how the data is structured.
The Admin API comes with a lot of other cool features like deduplication, self-discovery and a ton of client libraries in various languages.
What is the purpose of the Sync API?
The Sync endpoint is part of the Admin API and designed to import and export large amounts of data. Currently, 300 products per second can be imported. Long-running processes, such as the creation of thumbnails, are executed via messaging queue services in the background. The sync API is currently in an early development stage so there is no documentation on that topic yet.
Example request data: JSON list of objects containing actions that are run in the order you’ve provided them.
The sync API has the same authorization as the Admin API. The sync API uses upsert for writing data. For those of you who are not familiar with upsert: In case your entity with the given ID exists, it will be updated - otherwise, it will be created. So compared to a normal INSERT you can be sure your data is not accidentally duplicated.
What is the purpose of the Sales Channel API?
The Sales channel API provides common storefront functionality. This endpoint provides all requirements for connecting your custom shop frontend, POS or any other sales channel. This makes it possible to implement completely new sales concepts using the Shopware platform.
Sales channels are your interface to talk to the storefront or to 3rd party services like Instagram or Facebook. The Sales Channel API does not use OAuth since a lot of 3rd party services are not capable of performing this kind of authentication. The custom header “sw-access-key” is used for this purpose. Most of the functionality is accessible without a customer login, like listing products. Only customer-specific requests have to be authenticated.
Although Shopware can be used in headless mode, a full-featured, integrated and powerful Storefront is included in the platform.
Unlike the Admin API, the Sales Channel API is a stateful interface. Each request contains a context token that usually works like a session. So throughout multiple requests, your cart, login status, and other data that is usually saved in the session are preserved.
The Sales Channel API is much smaller than the Admin API because not every entity can be queried. Instead, it encapsulates a whole lot more of business logic which is necessary to build lean and performant solutions on top of the API.
On Github, we published several experiments to show how easy it is to use the Sales Channel API. Altogether there is a OnePageShop, a Shop-Snippet and an Alexa skill.
It has never been so easy to connect third-party systems to Shopware, let alone build your custom storefronts or to enable even greater customization.
Despite all the new functions, this is not at the expense of performance. The current benchmarks for the API are already very promising and enable ERP integrations to realize new synchronization concepts.
Stay up to date
You are interested in further developer content? Then follow us and be the first to be informed about product releases, updates, security notices, the Shopware Academy, and other important developer topics.