# Availability

### What you need to know:

The OCTo specification outlines a number of types of inventory calls.  We implement the following OCTo availability calls:

`POST /suppliers/:id/availability/` this endpoint will return a single availability object for each day, based on the request parameters.  You **MUST** perform this step to obtain the `availabilityId` to perform a sale transaction. &#x20;

You must pass in one of the following combinations of parameters for this endpoint:

* `localDate`
* `localDateStart` and `localDateEnd`
* `availabilityIds`

Example of `POST` `/availability/` :

```javascript
POST /availability/
{
  "productId": "cabfc194-9443-40fa-8342-85ed9d8ec58c",
  "optionId": "DEFAULT",
  "localDateStart": "2024-10-10",
  "localDateEnd": "2024-10-20",
  "units": [
    { "id": "seniors_83af6d2c-1c35-4728-ac03-3418a75c5579", "quantity": 2 },
    { "id": "adults_0e064227-c793-426b-857c-2d1fcba62582", "quantity": 1 }
  ]
}
```

## Check Availability

<mark style="color:green;">`POST`</mark> `https://api.zaui.io/octo/availability`

Determines the current availability of a product. &#x20;

#### Request Body

| Name                                        | Type        | Description                                          |
| ------------------------------------------- | ----------- | ---------------------------------------------------- |
| productId<mark style="color:red;">\*</mark> | string/uuid | The product ID                                       |
| optionId<mark style="color:red;">\*</mark>  | string      | The option ID                                        |
| localDateStart                              | string      | Travel start date to search.  (YYYY-MM-DD)           |
| localDateEnd                                | string      | Travel end date to search.  (YYYY-MM-DD)             |
| units\[].id                                 | string/uuid | seniors or adults or students or children or infants |
| units\[].quantity                           | string      | The unit quantity                                    |
| localDate                                   | string      | The local date to query (Format: YYYY-MM-DD)         |
| availabilityIds                             | array       | Filter the results by given ids                      |

{% tabs %}
{% tab title="200 " %}

```javascript
[
    {
        "id": "2023-01-11T10:00:00-08:00",
        "localDateTimeStart": "2023-01-11T10:00:00-08:00",
        "localDateTimeEnd": "2023-01-11T12:00:00-08:00",
        "allDay": false,
        "available": true,
        "status": "FREESALE",
        "vacancies": null,
        "capacity": null,
        "maxUnits": 10000,
        "utcCutoffAt": "2023-01-11T23:00:00Z",
        "openingHours": {
            "from": "06:00",
            "to": "20:00"
        }
    },
    {
        "id": "2023-01-12T10:00:00-08:00",
        "localDateTimeStart": "2023-01-12T10:00:00-08:00",
        "localDateTimeEnd": "2023-01-12T12:00:00-08:00",
        "allDay": false,
        "available": true,
        "status": "FREESALE",
        "vacancies": null,
        "capacity": null,
        "maxUnits": 10000,
        "utcCutoffAt": "2023-01-12T23:00:00Z",
        "openingHours": [
            {
                "from": "06:00",
                "to": "20:00"
            }
        ]
    },
    {
        "id": "2023-01-13T10:00:00-08:00",
        "localDateTimeStart": "2023-01-13T10:00:00-08:00",
        "localDateTimeEnd": "2023-01-13T12:00:00-08:00",
        "allDay": false,
        "available": true,
        "status": "FREESALE",
        "vacancies": null,
        "capacity": null,
        "maxUnits": 10000,
        "utcCutoffAt": "2023-01-13T23:00:00Z",
        "openingHours": [
            {
                "from": "06:00",
                "to": "20:00"
            }
        ]
    },
    {
        "id": "2023-01-14T10:00:00-08:00",
        "localDateTimeStart": "2023-01-14T10:00:00-08:00",
        "localDateTimeEnd": "2023-01-14T12:00:00-08:00",
        "allDay": false,
        "available": true,
        "status": "FREESALE",
        "vacancies": null,
        "capacity": null,
        "maxUnits": 10000,
        "utcCutoffAt": "2023-01-14T23:00:00Z",
        "openingHours": [
            {
                "from": "06:00",
                "to": "20:00"
            }
        ]
    },
    {
        "id": "2023-01-15T10:00:00-08:00",
        "localDateTimeStart": "2023-01-15T10:00:00-08:00",
        "localDateTimeEnd": "2023-01-15T12:00:00-08:00",
        "allDay": false,
        "available": true,
        "status": "FREESALE",
        "vacancies": null,
        "capacity": null,
        "maxUnits": 10000,
        "utcCutoffAt": "2023-01-15T23:00:00Z",
        "openingHours": [
            {
                "from": "06:00",
                "to": "20:00"
            }
        ]
    },
    {
        "id": "2023-01-16T10:00:00-08:00",
        "localDateTimeStart": "2023-01-16T10:00:00-08:00",
        "localDateTimeEnd": "2023-01-16T12:00:00-08:00",
        "allDay": false,
        "available": true,
        "status": "FREESALE",
        "vacancies": null,
        "capacity": null,
        "maxUnits": 10000,
        "utcCutoffAt": "2023-01-16T23:00:00Z",
        "openingHours": [
            {
                "from": "06:00",
                "to": "20:00"
            }
        ]
    },
    {
        "id": "2023-01-17T10:00:00-08:00",
        "localDateTimeStart": "2023-01-17T10:00:00-08:00",
        "localDateTimeEnd": "2023-01-17T12:00:00-08:00",
        "allDay": false,
        "available": true,
        "status": "FREESALE",
        "vacancies": null,
        "capacity": null,
        "maxUnits": 10000,
        "utcCutoffAt": "2023-01-17T23:00:00Z",
        "openingHours": [
            {
                "from": "06:00",
                "to": "20:00"
            }
        ]
    },
    {
        "id": "2023-01-18T10:00:00-08:00",
        "localDateTimeStart": "2023-01-18T10:00:00-08:00",
        "localDateTimeEnd": "2023-01-18T12:00:00-08:00",
        "allDay": false,
        "available": true,
        "status": "FREESALE",
        "vacancies": null,
        "capacity": null,
        "maxUnits": 10000,
        "utcCutoffAt": "2023-01-18T23:00:00Z",
        "openingHours": [
            {
                "from": "06:00",
                "to": "20:00"
            }
        ]
    },
    {
        "id": "2023-01-19T10:00:00-08:00",
        "localDateTimeStart": "2023-01-19T10:00:00-08:00",
        "localDateTimeEnd": "2023-01-19T12:00:00-08:00",
        "allDay": false,
        "available": true,
        "status": "FREESALE",
        "vacancies": null,
        "capacity": null,
        "maxUnits": 10000,
        "utcCutoffAt": "2023-01-19T23:00:00Z",
        "openingHours": [
            {
                "from": "06:00",
                "to": "20:00"
            }
        ]
    },
    {
        "id": "2023-01-20T10:00:00-08:00",
        "localDateTimeStart": "2023-01-20T10:00:00-08:00",
        "localDateTimeEnd": "2023-01-20T12:00:00-08:00",
        "allDay": false,
        "available": true,
        "status": "FREESALE",
        "vacancies": null,
        "capacity": null,
        "maxUnits": 10000,
        "utcCutoffAt": "2023-01-20T23:00:00Z",
        "openingHours": [
            {
                "from": "06:00",
                "to": "20:00"
            }
        ]
    }
]
```

{% endtab %}
{% endtabs %}

## Check Availability Calendar

<mark style="color:green;">`POST`</mark> `https://api.zaui.io/octo/availability/calendar/`

Returns a single object per day. Designed for large date ranges used to populate an availability calendar.

#### Request Body

| Name                                             | Type        | Description                              |
| ------------------------------------------------ | ----------- | ---------------------------------------- |
| productId<mark style="color:red;">\*</mark>      | string/uuid | The product ID                           |
| optionId<mark style="color:red;">\*</mark>       | string      | The option ID                            |
| localDateStart<mark style="color:red;">\*</mark> | string      | Start date to query (Format: YYYY-MM-DD) |
| localDateEnd<mark style="color:red;">\*</mark>   | string      | End date to query (Format: YYYY-MM-DD)   |
| units                                            | array       | A list of units                          |
| units.id<mark style="color:red;">\*</mark>       | string/uuid | The unit id                              |
| units.quantity<mark style="color:red;">\*</mark> | int         | The quantity of the unit                 |

{% tabs %}
{% tab title="200: OK " %}

```javascript
[
    {
        "localDate": "2023-01-01",
        "available": true,
        "status": "AVAILABLE",
        "openingHours": [
            {
                "from": "06:00",
                "to": "20:00"
            }
        ],
        "vacancies": 14,
        "capacity": 14
    },
    {
        "localDate": "2023-01-02",
        "available": true,
        "status": "AVAILABLE",
        "openingHours": [
            {
                "from": "06:00",
                "to": "20:00"
            }
        ],
        "vacancies": 14,
        "capacity": 14
    },
    {
        "localDate": "2023-01-03",
        "available": true,
        "status": "AVAILABLE",
        "openingHours": [
            {
                "from": "06:00",
                "to": "20:00"
            }
        ],
        "vacancies": 14,
        "capacity": 14
    }
]
```

{% endtab %}
{% endtabs %}

Response Objects:

| Field                 | Description                                                                                                                                                                                                                                                                                                                                        |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`                  | The availability ID.  **You need this for making a Booking.**                                                                                                                                                                                                                                                                                      |
| `localDateTimeStart`  | The travel date/time for this availability, in the same time zone as the supplier's product.                                                                                                                                                                                                                                                       |
| `localDateTimeEnd`    | The travel date/time for this availability, in the same time zone as the supplier's product.                                                                                                                                                                                                                                                       |
| `allDay`              | Boolean indicating an all day or a fixed departure time.  **If true, then there will be no other available objects on the same day.**                                                                                                                                                                                                              |
| `available`           | Whether there is availability for this date/time slot.                                                                                                                                                                                                                                                                                             |
| `status`              | <p>The status of that date. Possible values are:</p><p><code>AVAILABLE</code> This availability is available for sale</p><p><code>FREESALE</code> This availability has no capacity and is available.</p><p><code>SOLD\_OUT</code> This availability is not available </p><p><code>LIMITED</code> This availability is available but limited. </p> |
| `vacancies`           | The remaining inventory.                                                                                                                                                                                                                                                                                                                           |
| `capacity`            | Total allowed inventory.                                                                                                                                                                                                                                                                                                                           |
| `maxUnits`            | Maximum number of units  that can be sold within one booking on this date/time slot.                                                                                                                                                                                                                                                               |
| `utcCutoffAt`         | The time by which the booking must be confirmed.                                                                                                                                                                                                                                                                                                   |
| `openingHours[].from` | When this product opens (HH:MM)                                                                                                                                                                                                                                                                                                                    |
| `openingHours[].to`   | When this product closes (HH:MM)                                                                                                                                                                                                                                                                                                                   |

{% hint style="info" %}
If the product status is `CLOSED` then there will be no availability object returned.
{% endhint %}
