Storefront API
Get started with the Storefront API.
The Storefront API delivers headless capabilities built directly into Umbraco Commerce. It allows you to retrieve and manage orders and other store-related entities in a JSON format. It lets you connect with them in different channels, using your preferred technology stack. This feature preserves the friendly editing experience of Umbraco, while also ensuring performant cart management facilities in a headless fashion. With its different extension points, you can tailor this API to fit a broad range of requirements.
Getting Started
As the Storefront API works alongside the Content Delivery API you must first have the Content Delivery API setup and enabled.
When the Content Delivery API is enabled, you will need to explicitly opt-in to the Storefront API. Below you will find the steps you need to take in order to configure it for your Umbraco project.
Register the Storefront API dependencies
Open your project's
Program.cs
file.Register the API dependencies by adding
.AddStorefrontApi()
inside a.AddUmbracoCommerce()
call:
Enable the Storefront API
Open your project's
appsettings.json
.Insert the
StorefrontApi
configuration section underUmbraco:Commerce
.Add the
Enabled
key and set its value totrue
:
Securing the Storefront API
In order to work with the Storefront API many of the endpoints require authorization. The authorization is implemented by means of an API Key that must be passed in the header of these requests. The API Key is defined as an additional app setting and can be any value you decide:
Concepts
Before exploring the API endpoints detailed below, there are a few concepts to keep in mind.
Endpoints
The Storefront API is broken down into a number of endpoints grouped by resource type. Select a resource type below to review the available endpoints.
Swagger UI
You can access a Swagger document for the Storefront API at {yourdomain}/umbraco/swagger
, selecting Umbraco Commerce Storefront API
from the definitions dropdown in the top right. From here you can see a full list of supported APIs, the parameters they accept and the expected payloads and responses.
Value Converters
As Umbraco Commerce uses content nodes as products, the Storefront API comes with some replacement value converters that automatically extend the default value converter functionality to return Storefront entities when accessed through the Content Delivery API. You don't need to do anything to enable these.
Store Picker - Returns a Store "Reference" by default, or a complete Store response object if the store picker property is being expanded.
Store Entity Picker - Returns an entity "Reference" by default, or a complete entity response object if the store entity picker property is being expanded.
Price - Returns a price for the product based on session information passed through in headers. See the "Session" concept detailed above.
Stock - Returns the stock level of the given product.
Variants - See notes on the variants value converter below.
Variants Value Converter
To help with common scenarios when working with variants, the Variants value converter will return a series of data items used when building a relevant UI.
attributes
will contain a list of "in use" attributes which means there is at least one variant content item that makes use of that attribute. These should be used to build the attribute options UI.items
returns a list of variant items. By default, this will return the attribute combinations, and whether it is the default combination but its content value will be empty. The content value can be populated by expanding the variants property through the Delivery API, however, it's important to know this could return a lot of data and be intensive. Instead, it is preferred to return the non-expanded value and use thevariantContentUrl
to fetch individual content items as they are requested. Theitems
collection should also be used to check if a combination exists as whilst the root levelattributes
collection contains all in-use attributes, it doesn't mean every possible combination of those attributes exists so you can use theitems
collection to validate a combination.variantContentUrl
as the URL to a specialized Delivery API route that can return a single variant item content based on a passed-in attribute combination.
Last updated