> ## Documentation Index
> Fetch the complete documentation index at: https://dokumentation.websale.de/llms.txt
> Use this file to discover all available pages before exploring further.

# Storefront API Session Handling

> Create and manage anonymous or authenticated sessions for the storefront via the Storefront API to keep cart, wish list, and user state consistent.

Storefront API Session Handling provides functions to create and manage sessions in the storefront. This makes it possible to use user states (e.g. anonymous visit or logged-in customer) as well as session-bound data such as shopping cart and wish list consistently across multiple requests.

The session is a component of the shop and is mandatory. For more information, see [here](https://websaleag-44ee7ea6.mintlify.app/konfiguration/general-allgemeine-shopeinstellungen#9-general-garbagecollection-sitzungsverwaltung-und-automatische-aufräumprozesse).

***

## Supported methods

List of all supported methods.

| **Command**                     | **Endpoints**             | **GET**             | **POST**              | **PUT**             | **DELETE**          |
| ------------------------------- | ------------------------- | ------------------- | --------------------- | ------------------- | ------------------- |
| Create session                  | `session/create`          | <Icon icon="ban" /> | <Icon icon="check" /> | <Icon icon="ban" /> | <Icon icon="ban" /> |
| Create link to a template page. | `session/prepareRedirect` | <Icon icon="ban" /> | <Icon icon="check" /> | <Icon icon="ban" /> | <Icon icon="ban" /> |

## Methods for session handling

These methods take care of session handling between API and storefront: First, new session IDs are generated as the technical basis for all further API calls. If needed, complete redirect links to template pages (e.g. checkout) are built up, including handover of the current session. Optional parameters can be used to specifically control target pages (e.g. a specific checkout step or highlights), while the actual session ID is securely embedded in the link.

### POST session/create

The following call creates a session ID.\
More info: [Storefront API Basics](/en/schnittstellen/storefront-api/storefront-api-basics)

```text theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
POST https://<your-shop>.de/api/v1/session/create
```

#### Example response

```json theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{
   "id" : "bc37dffbf7a3d067a1b0a3040143c5a8d1a1d8651f79159f59d81705c9733c49"
}
```

### POST session/prepareRedirect

The following call generates a complete link to a template page (e.g. "checkout.htm") and carries the current session over into the storefront. Optionally, additional parameters can be passed that the target template reads (e.g. to directly open a specific checkout step).

Using this method makes sense if your shop is set up in a mixed way, i.e. if some parts have been created with the [WEBSALE template theme](/en/frontend/die-basics/template-theme) and other parts with the Storefront API. The endpoint ensures that both parts use the same session.

**Example request that creates a complete link to the template page** `checkout` **and takes the current session along**

```json theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{
  "viewIdentifier": "checkout"
}
```

#### Parameter overview

| **Parameter**    | **Type** | **Description**                                                                                                                                                                                                                                                        |
| ---------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `x-session`      | string   | **Required field**<br />ID of the current session.   More information: [Storefront API Basics](../storefront-api/storefront-api-basics.md#2-session-handling)                                                                                                          |
| `viewIdentifier` | string   | **Required field**<br />The ID configured in `storefrontApi.redirects`.   More about this:   [storefrontApi - Storefront API](/konfiguration/storefrontapi-storefront-api#storefrontapiredirects-template-weiterleitung)                                               |
| `parameters`     | object   | Optional values that are passed to the target page and are available there, for example, via `$wsViews.storefrontApiLinkParameters`.      Example:  `{   "viewIdentifier": "checkout",   "params":    {      "step": "address",      "highlight": "shipping"      } }` |

#### Example response

```json theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{
  "storeFrontLink": "https://demo.shop.websale.biz/checkout?sessionKey=U2swGmPcfOeSsVPLF4wCXw2wmYDDcuzh"
}
```

(complete URL to the target template page including session handover)

#### Error codes

| **Code**                       | **Description**                                                  |
| ------------------------------ | ---------------------------------------------------------------- |
| `redirectNotFound`             | No configuration entry found for the specified `viewIdentifier`. |
| `redisServicePoolInaccessible` | Internal problem. Please contact WEBSALE support.                |
| `redisServiceNotFound`         | Internal problem. Please contact WEBSALE support.                |
