> For the complete documentation index, see [llms.txt](https://developer.emporix.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.emporix.io/api-documentation/api-guides/orders/availability/availability.md). Agents can also search and read this documentation through its [MCP server](https://developer.emporix.io/~gitbook/mcp).

# Availability Tutorial

## How to specify availability, popularity, or stock level for a product

{% hint style="info" %}
This tutorial describes how to specify availability, popularity, and stock level for a single product.
{% endhint %}

Information about a specific product's availability, popularity, and stock levels is stored inside the `Availability` object.

Take a look at the relationships between the `Availability` object and other resources in the Emporix Commerce Engine:

```mermaid
---
config:
  layout: fixed
  theme: base
  look: classic
  themeVariables:
    background: transparent
    lineColor: "#9CBBE3"
    arrowheadColor: "#9CBBE3"
    edgeLabelBackground: "#FFC128"
    edgeLabelTextColor: "#4C5359"
---
classDiagram
    class Site {
        _code : String
        ...
    }

    class Product {
        _id : String
        ...
    }

    class Availability {
        _id : String
        site : String
        stockLevel : Double
        available : Boolean
        productId : String
        popularity : Integer
        createdAt : String (ISO 8601)
        modifiedAt : String (ISO 8601)
        distributionChannel : DistributionChannel
    }

    class DistributionChannel {
        ASSORTMENT
        HOME_DELIVERY
        PICKUP
    }

    Site --> Availability : site
    Product --> Availability : productId
    DistributionChannel --> Availability : distributionChannel

    style Availability fill:#F2F6FA, stroke:#4C5359
    style Product fill:#F2F6FA, stroke:#4C5359
    style Site fill:#F2F6FA, stroke:#4C5359
    style DistributionChannel fill:#F2F6FA, stroke:#4C5359
```

### Before you start

Make sure you created a product. For more information, check out [How to add your first product](https://developer.emporix.io/api-documentation/api-guides/products-labels-and-brands/product-service/product.md#how-to-add-your-first-product).

### Create the `Availability` object

{% hint style="warning" %}
We recommend not to create a new product availability for a `main` sitecode. A site named `main` works as an aggregator of availability data from other sites. It's not possible to later retrieve availability for a single site when it's called `main`. Use a different sitecode for creating product availabilities.
{% endhint %}

To add availability-related information for a specific product, you need to send a request to the [Creating a new availability for a product](https://developer.emporix.io/api-documentation/api-guides/orders/availability/api-reference/availabilities#post-availability-tenant-availability-productid-site) endpoint.

{% hint style="success" %}
To test the endpoint, open the API reference or check the example of a curl request.
{% endhint %}

{% content-ref url="/pages/nhisEohe0gxRuvkLUiQ4" %}
[API Reference](https://developer.emporix.io/api-documentation/api-guides/orders/availability/api-reference.md)
{% endcontent-ref %}

```bash
curl -i -X POST \
  'https://api.emporix.io/availability/{tenant}/availability/{productId}/{site}' \
  -H 'Authorization: Bearer {{OAUTH2_ACCESS_TOKEN}}' \
  -H 'Content-Type: application/json' \
  -d '{
    "stockLevel": 10,
    "available": true,
    "popularity": 5,
    "distributionChannel": "ASSORTMENT",
    "metadata": {
      "mixins": {
        "productCustomAttributes": "https://res.cloudinary.com/saas-ag/raw/upload/schemata/productCustomAttributesMixIn.v29.json"
      }
    },
    "mixins": {
      "productCustomAttributes": {
        "minOrderQuantity": 2
      }
    }
  }'
```

### Manage product availabilities in bulk

You can also manage multiple availabilities for a product at once. A single product can have different availabilities per site, so each availability entry is identified by the combination of `productId` and `site`.

To create or update multiple product availabilities at once, send a request to one of the following endpoints:

* [Creating multiple product availabilities](https://developer.emporix.io/api-documentation/api-guides/orders/availability/api-reference/availabilities#post-availability-tenant-availability-bulk)
* [Upserting multiple availabilities information of a product](https://developer.emporix.io/api-documentation/api-guides/orders/availability/api-reference/availabilities#put-availability-tenant-availability-bulk)
* [Partially updating multiple availabilities](https://developer.emporix.io/api-documentation/api-guides/orders/availability/api-reference/availabilities#patch-availability-tenant-availability-bulk)

Example bulk create request:

```bash
curl -i -X POST \
  'https://api.emporix.io/availability/{tenant}/availability/bulk' \
  -H 'Authorization: Bearer {{OAUTH2_ACCESS_TOKEN}}' \
  -H 'Content-Type: application/json' \
  -d '[
    {
      "productId": "PRODUCT-1",
      "site": "site-a",
      "stockLevel": 10,
      "available": true
    },
    {
      "productId": "PRODUCT-1",
      "site": "site-b",
      "stockLevel": 0,
      "available": false
    }
  ]'
```

In this example, the same product has different availability on two sites: `site-a` and `site-b` where both records are created in a single bulk operation.

### Partially update product availabilities

To change only selected fields on a stored availability, send a JSON Patch array. Use `REPLACE` to set a field and `REMOVE` to clear it. Fields you do not name stay unchanged. A missing availability returns `404` and is not created.

{% hint style="warning" %}
The `availability.availability_manage` scope is required. The `availability.availability_manage_by_vendor` scope is only required when updating availabilities that belong to the vendor.
{% endhint %}

For one availability, send a request to the [Partially updating availability information of a product](https://developer.emporix.io/api-documentation/api-guides/orders/availability/api-reference/availabilities#patch-availability-tenant-availability-productid-site) endpoint:

```bash
curl -i -X PATCH \
  'https://api.emporix.io/availability/{{tenant}}/availability/{{productId}}/{{site}}' \
  -H 'Authorization: Bearer {{OAUTH2_ACCESS_TOKEN}}' \
  -H 'Content-Type: application/json' \
  -d '[
  {
    "op": "REPLACE",
    "path": "/stockLevel",
    "value": 42
  }
]'
```

To partially update up to 200 stored availabilities in one call, send a request to the [Partially updating multiple availabilities](https://developer.emporix.io/api-documentation/api-guides/orders/availability/api-reference/availabilities#patch-availability-tenant-availability-bulk) endpoint. Each item identifies one availability by `productId` and `site`, and `data` holds the patch operations. A valid call returns `207` with one result for each item.

```bash
curl -i -X PATCH \
  'https://api.emporix.io/availability/{{tenant}}/availability/bulk' \
  -H 'Authorization: Bearer {{OAUTH2_ACCESS_TOKEN}}' \
  -H 'Content-Type: application/json' \
  -d '[
  {
    "productId": "5f7c996173fc281cdd412345",
    "site": "shop1",
    "data": [
      {
        "op": "REPLACE",
        "path": "/stockLevel",
        "value": 42
      }
    ]
  },
  {
    "productId": "5f7c996173fc281cdd412346",
    "site": "shop1",
    "data": [
      {
        "op": "REPLACE",
        "path": "/stockLevel",
        "value": 7
      }
    ]
  }
]'
```

### Retrieve the availability information of a product

To check if a product's availability was added successfully, you need to send a request to the [Retrieving a product's availability](https://developer.emporix.io/api-documentation/api-guides/orders/availability/api-reference/availabilities#post-availability-tenant-availability-search) endpoint with the product's ID in the request body.

{% hint style="info" %}
You can also retrieve availability information for multiple products at once by sending a request to the [Retrieving product availabilities for a site](https://developer.emporix.io/api-documentation/api-guides/orders/availability/api-reference/availabilities#post-availability-tenant-availability-search) endpoint.
{% endhint %}

{% hint style="success" %}
To test the endpoint, open the API reference or check the example of a curl request.
{% endhint %}

{% content-ref url="/pages/nhisEohe0gxRuvkLUiQ4" %}
[API Reference](https://developer.emporix.io/api-documentation/api-guides/orders/availability/api-reference.md)
{% endcontent-ref %}

```bash
curl -i -X GET \
  'https://api.emporix.io/availability/{tenant}/availability/{productId}/{site}' \
  -H 'Authorization: Bearer {{OAUTH2_ACCESS_TOKEN}}'
```

## How to calculate a product bundle's stock level

The Availability Service makes it possible to automatically calculate the stock level of a product bundle. The value is always equal to the lowest stock level of the bundled products.

{% hint style="warning" %}
For a product bundle's availability to be calculated, all products in the bundle need to have their availability and stock levels specified. Otherwise, the bundle will be treated as unavailable.
{% endhint %}

### Before you start

Make sure the following requirements are fulfilled:

* You have already created all products that make up the bundle.

{% hint style="info" %}
For instructions, check out [How to add your first product](https://developer.emporix.io/api-documentation/api-guides/products-labels-and-brands/product-service/product.md#how-to-add-your-first-product).
{% endhint %}

* You have already specified stock levels for all products that make up the bundle.

{% hint style="info" %}
For instructions, check out [How to specify availability, popularity, or stock level for a product](#how-to-specify-availability-popularity-or-stock-level-for-a-product).
{% endhint %}

* You have already created a product bundle.

{% hint style="info" %}
For instructions, check out [How to create a bundle of personalized products](https://developer.emporix.io/api-documentation/api-guides/products-labels-and-brands/product-service/product.md#how-to-create-a-bundle-of-personalized-products).
{% endhint %}

### Retrieve the product bundle's availability information

To find out what the stock level of a product bundle is, you need to send a request to the [Retrieving a product's availability](https://developer.emporix.io/api-documentation/api-guides/orders/availability/api-reference/availabilities#get-availability-tenant-availability-productid-site) endpoint with the product bundle's ID in the path.

{% hint style="success" %}
To test the endpoint, open the API reference or check the example of a curl request.
{% endhint %}

{% content-ref url="/pages/nhisEohe0gxRuvkLUiQ4" %}
[API Reference](https://developer.emporix.io/api-documentation/api-guides/orders/availability/api-reference.md)
{% endcontent-ref %}

```bash
curl -i -X GET \
  'https://api.emporix.io/availability/{tenant}/availability/{productId}/{site}' \
  -H 'Authorization: Bearer {{OAUTH2_ACCESS_TOKEN}}'
```

The response includes both the availability information of the bundle as a whole, as well as the bundled products.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developer.emporix.io/api-documentation/api-guides/orders/availability/availability.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
