> For the complete documentation index, see [llms.txt](https://docs.channex.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.channex.io/channel-api-examples/mg-bedbank.md).

# MG Bedbank

This guide walks through creating a channel connection between Channex and MG Bedbank over the API: discovering the adapter, validating the hotel ID, reading the rooms and rates on both sides, building the mapping, and creating and activating the connection.

A **channel connection** (a *channel*) links rate plans of a Channex property to rooms and rates on the OTA side. Once the connection is active, Channex pushes availability, rates and restrictions to MG Bedbank and receives bookings back.

Every OTA has its own API and data model, so the connection settings and the mapping settings differ per channel. The flow below is shared by most channels (Booking.com, Expedia, Agoda, Open Channel–based OTAs and others); the payloads shown are the MG Bedbank ones. Airbnb is the exception — it requires an OAuth authorization step and is covered by a separate guide.

All endpoints require authentication with an API key, sent in the `user-api-key` header.

### Before you start

The hotel must have Channex selected as its channel manager (connectivity partner) on the MG Bedbank side. Channex connects to MG Bedbank with its own partner credentials, so the only thing needed from the hotel is its **MG Bedbank Hotel ID**. If the hotel cannot find the channel manager section in MG, it should ask MG support to enable the connection to Channex.

### The flow at a glance

1. Get the adapter descriptor — what settings and mapping fields MG Bedbank needs.
2. Collect the settings from the user and run a test connection.
3. Get the mapping details — the rooms and rates on the MG Bedbank side.
4. Collect the Channex side — the property, its room types and rate plans.
5. Build the mapping structure.
6. Create the connection.
7. Activate it.

### 1. Get the adapter descriptor

Each channel is described by an **adapter descriptor**: the settings it needs (`params`) and the per-mapping fields it needs (`rate_params`).

```
GET /api/v1/channels/adapter?code=MGBedbank
```

The full catalog of adapters is available at `GET /api/v1/channels/list`.

Response (abridged):

```json
{
  "data": {
    "code": "MGBedbank",
    "title": "MG Bedbank",
    "kind": "meta",
    "actions": [],
    "params": {
      "hotel_id": {
        "position": 0,
        "type": "string",
        "title": "Hotel ID"
      },
      "send_email_notifications": {
        "default": false,
        "position": 1,
        "type": "boolean",
        "title": "Send Property Notification"
      },
      "email": {
        "position": 2,
        "type": "string",
        "title": "Property Email",
        "rules": [
          {
            "apply": "hidden",
            "when": false,
            "influence_field": "send_email_notifications",
            "with_value": ""
          }
        ]
      },
      "min_stay_type": {
        "default": "Arrival",
        "position": 3,
        "type": "switch",
        "options": ["Arrival", "Through"],
        "title": "Min Stay Type"
      }
    },
    "rate_params": {
      "rate_plan_code": { "position": 0, "title": "Rate", "type": "string" },
      "room_type_code": { "position": 1, "title": "Room", "type": "string" },
      "occupancy": { "position": 2, "title": "Occupancy", "type": "integer" },
      "pricing_type": { "position": 3, "title": "PricingType", "type": "string" },
      "primary_occ": { "position": 4, "title": "Primary Occupancy", "type": "boolean" }
    }
  }
}
```

What to read from it:

* **`params`** — the connection settings to collect from the user. Each entry describes one field: `title` (English label), `type` (`string`, `password`, `integer`, `boolean`, `select`, `switch`, `hidden`), `position` (ordering for a UI), `default`, `options` (for `select` and `switch` fields) and conditional display `rules`.
* **`rate_params`** — the fields each rate plan mapping must carry (step 5), described the same way.

For MG Bedbank, the only setting to collect from the user is **`hotel_id`** — the MG Bedbank Hotel ID. The remaining settings have sensible defaults; see the settings reference.

### 2. Test the connection

Before creating anything, validate the collected settings with a test connection:

```
POST /api/v1/channels/test_connection
```

```json
{
  "channel": "MGBedbank",
  "settings": {
    "hotel_id": "253495"
  }
}
```

`channel` is the adapter code from the descriptor; `settings` is the object built from `params`. Channex requests the hotel's product (its rooms and rates) from MG Bedbank with the given Hotel ID.

Response:

```json
{
  "data": {
    "success": true,
    "errors": null
  }
}
```

`success: true` means MG Bedbank recognises the Hotel ID and the hotel is connected to Channex on the MG Bedbank side. On failure the response is still `200 OK` with `success: false` — check the `success` field, not the status code. A failure usually means a wrong Hotel ID, or that the hotel has not selected Channex as its channel manager in MG yet.

### 3. Get the mapping details

Next, fetch the rooms and rates the hotel exposes on the MG Bedbank side:

```
POST /api/v1/channels/mapping_details
```

The payload is the same as for the test connection:

```json
{
  "channel": "MGBedbank",
  "settings": {
    "hotel_id": "253495"
  }
}
```

Response (abridged):

```json
{
  "data": {
    "pricing_type": "OBP",
    "rooms": [
      {
        "id": "RM_253495_0",
        "title": "DELUXE",
        "max_children": 0,
        "rates": [
          {
            "id": "RC_253495_101_2",
            "title": "CHANNEX RO ALL",
            "max_persons": 4,
            "occupancies": [1, 2, 3, 4]
          },
          {
            "id": "RC_253495_101_3",
            "title": "CHANNEX BABF ALL",
            "max_persons": 4,
            "occupancies": [1, 2, 3, 4]
          }
        ]
      },
      {
        "id": "RM_253495_1",
        "title": "STANDARD",
        "max_children": 0,
        "rates": [
          {
            "id": "RC_253495_101_2",
            "title": "CHANNEX RO ALL",
            "max_persons": 3,
            "occupancies": [1, 2, 3]
          },
          {
            "id": "RC_253495_101_3",
            "title": "CHANNEX BABF ALL",
            "max_persons": 3,
            "occupancies": [1, 2, 3]
          }
        ]
      }
    ]
  }
}
```

Every channel returns its own mapping-details shape; this one is MG Bedbank's.

**`pricing_type`** — the hotel's pricing model, derived from the hotel's product on MG Bedbank:

* `OBP` — occupancy-based pricing: MG Bedbank lists per-guest occupancy options for the hotel's rooms, and each rate carries a price per occupancy option.
* `Standard` — per-room pricing: no occupancy options are listed, and each rate carries one price per room.

**`rooms`** — the rooms available for mapping. Each room carries:

| Field          | Description                                                        |
| -------------- | ------------------------------------------------------------------ |
| `id`           | Room type code on the MG Bedbank side.                             |
| `title`        | Room title.                                                        |
| `max_children` | Always `0` — MG Bedbank does not report a children limit per room. |
| `rates`        | Rates of the room.                                                 |

Each rate carries:

| Field         | Description                                                                                                                    |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `id`          | Rate plan code on the MG Bedbank side.                                                                                         |
| `title`       | Rate title.                                                                                                                    |
| `max_persons` | Maximum number of adults the room accepts. `1` when MG Bedbank reports no occupancy options for the room (`Standard` pricing). |
| `occupancies` | Occupancy options of the rate on this room: every value from 1 to `max_persons`. Present for `OBP` rates only.                 |

The same rate can be offered on several rooms: it appears under each room it is sold on, with the occupancy options it has there, and a mapping always targets one room + rate pair.

### 4. Collect the Channex side

MG Bedbank connections are one-to-one: **one connection maps exactly one Channex property to one MG Bedbank hotel**. Pick the property to connect, then fetch its room types and rate plans through the `options` endpoints:

```
GET /api/v1/room_types/options?filter[property_id]={property_id}
GET /api/v1/rate_plans/options?filter[property_id]={property_id}&multi_occupancy=true
```

Enable `multi_occupancy` on the rate plans request: for occupancy-based rate plans it expands each occupancy option into its own entry, which is exactly the granularity MG Bedbank OBP mappings need.

Prices are pushed to MG Bedbank in the currency of the mapped Channex rate plan, so map rate plans whose currency matches the currency the hotel uses on MG Bedbank.

### 5. Build the mapping structure

The mapping is a list of `rate_plans` entries, one per (Channex rate plan occupancy → MG Bedbank room/rate/occupancy) pair:

```json
{
  "rate_plan_id": "a35f1fd4-63c6-4fbc-8fbe-359869bd9958",
  "settings": {
    "room_type_code": "RM_253495_0",
    "rate_plan_code": "RC_253495_101_2",
    "occupancy": 2,
    "pricing_type": "OBP",
    "primary_occ": true
  }
}
```

**`rate_plan_id`** — the Channex rate plan UUID (from step 4).

**`settings`** — the fields declared by `rate_params` in the adapter descriptor:

| Field            | Description                                                                                                                                                                                         |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `room_type_code` | Room type code on the MG Bedbank side.                                                                                                                                                              |
| `rate_plan_code` | Rate plan code on the MG Bedbank side.                                                                                                                                                              |
| `occupancy`      | The occupancy option of the MG Bedbank rate this mapping serves — the number of guests its price is sent for. Required for both pricing models — for `Standard` rates use the rate's `max_persons`. |
| `pricing_type`   | The hotel's pricing model — copy it from the mapping details (`OBP` or `Standard`).                                                                                                                 |
| `primary_occ`    | Whether this mapping is the primary one for its room + rate pair. See below.                                                                                                                        |

Mark **exactly one mapping of each room + rate pair** as primary. For `OBP` hotels, create one mapping per occupancy option you want to sell; for `Standard` hotels, a room + rate pair has a single mapping.

Channex sends one update per room + rate pair and date to MG Bedbank:

* the prices of all mapped occupancies of the pair are sent together — when the price of one occupancy changes, the current prices of the other mapped occupancies are sent along with it;
* availability and restrictions are sent once for the pair — when its mappings carry different values, the values of the **primary** mapping are used.

A full mapping for one MG Bedbank OBP rate sold at two occupancies:

```json
[
  {
    "rate_plan_id": "a35f1fd4-63c6-4fbc-8fbe-359869bd9958",
    "settings": {
      "room_type_code": "RM_253495_0",
      "rate_plan_code": "RC_253495_101_2",
      "occupancy": 2,
      "pricing_type": "OBP",
      "primary_occ": true
    }
  },
  {
    "rate_plan_id": "2a0c416b-d8e6-4950-b52e-e7821030fd9d",
    "settings": {
      "room_type_code": "RM_253495_0",
      "rate_plan_code": "RC_253495_101_2",
      "occupancy": 1,
      "pricing_type": "OBP",
      "primary_occ": false
    }
  }
]
```

### 6. Create the connection

```
POST /api/v1/channels
```

The payload is wrapped in a `channel` key:

```json
{
  "channel": {
    "channel": "MGBedbank",
    "group_id": "60674dd6-1aeb-4c41-9e0c-8ffb378a4570",
    "title": "MG Bedbank Channel",
    "properties": ["acb388d9-546b-42fc-9ae2-baf00e7f0d8c"],
    "settings": {
      "hotel_id": "253495",
      "min_stay_type": "Arrival"
    },
    "rate_plans": [
      {
        "rate_plan_id": "a35f1fd4-63c6-4fbc-8fbe-359869bd9958",
        "settings": {
          "room_type_code": "RM_253495_0",
          "rate_plan_code": "RC_253495_101_2",
          "occupancy": 2,
          "pricing_type": "OBP",
          "primary_occ": true
        }
      },
      {
        "rate_plan_id": "2a0c416b-d8e6-4950-b52e-e7821030fd9d",
        "settings": {
          "room_type_code": "RM_253495_0",
          "rate_plan_code": "RC_253495_101_2",
          "occupancy": 1,
          "pricing_type": "OBP",
          "primary_occ": false
        }
      }
    ]
  }
}
```

| Field        | Description                                                                                                |
| ------------ | ---------------------------------------------------------------------------------------------------------- |
| `channel`    | The adapter code from the descriptor.                                                                      |
| `group_id`   | UUID of the group the connection belongs to. Required.                                                     |
| `title`      | Connection title. Optional — generated from the channel and property names when omitted.                   |
| `properties` | UUIDs of the connected properties. One property for MG Bedbank.                                            |
| `settings`   | The connection settings built from `params` — the same object the test connection validated.               |
| `rate_plans` | The mapping structure from step 5. Optional — mappings can also be added later by updating the connection. |

The response is `201 Created` with the channel connection resource (abridged):

```json
{
  "data": {
    "type": "channel",
    "id": "ca4ac55f-3be1-4039-9542-21e8285ffbf9",
    "attributes": {
      "id": "ca4ac55f-3be1-4039-9542-21e8285ffbf9",
      "title": "MG Bedbank Channel",
      "channel": "MGBedbank",
      "is_active": false,
      "actions": [],
      "properties": ["acb388d9-546b-42fc-9ae2-baf00e7f0d8c"],
      "settings": {
        "hotel_id": "253495",
        "min_stay_type": "Arrival"
      },
      "rate_plans": [
        {
          "id": "9d7e45b3-367b-4286-a081-17a6c8d3c62e",
          "rate_plan_id": "a35f1fd4-63c6-4fbc-8fbe-359869bd9958",
          "settings": {
            "room_type_code": "RM_253495_0",
            "rate_plan_code": "RC_253495_101_2",
            "occupancy": 2,
            "pricing_type": "OBP",
            "primary_occ": true
          }
        },
        {
          "id": "0f6fe97e-ab8b-4f0b-a1cd-dc3500f18295",
          "rate_plan_id": "2a0c416b-d8e6-4950-b52e-e7821030fd9d",
          "settings": {
            "room_type_code": "RM_253495_0",
            "rate_plan_code": "RC_253495_101_2",
            "occupancy": 1,
            "pricing_type": "OBP",
            "primary_occ": false
          }
        }
      ]
    },
    "relationships": {
      "group": {
        "data": { "id": "60674dd6-1aeb-4c41-9e0c-8ffb378a4570", "type": "group" }
      },
      "properties": {
        "data": [
          { "id": "acb388d9-546b-42fc-9ae2-baf00e7f0d8c", "type": "property" }
        ]
      }
    }
  }
}
```

Note that the connection **starts disabled**: `is_active` in the create payload has no effect — a new connection is always created with `is_active: false`. Activation is a separate, explicit step.

Only one connection per MG Bedbank `hotel_id` is allowed on Channex.

### 7. Activate the connection

```
POST /api/v1/channels/{channel_id}/activate
```

No payload. Activation requires the connection to have at least one property and at least one rate plan mapping; activating starts the synchronization — Channex pushes the full current availability, rates and restrictions to MG Bedbank and begins receiving bookings. MG Bedbank delivers new, modified and cancelled bookings to Channex itself; no extra setup is needed.

The counterpart is `POST /api/v1/channels/{channel_id}/deactivate`, which stops the synchronization but keeps the connection and its mappings.

### Updating a connection

```
PUT /api/v1/channels/{channel_id}
```

The payload has the same shape as for create (wrapped in `channel`). Two rules matter:

* **`channel` cannot be changed** — a different adapter code is rejected.
* **`rate_plans`, when present, replaces the whole mapping set.** A stored mapping missing from the list is removed, and a mapping sent with `settings: null` is removed as well. Omit `rate_plans` entirely to keep the stored mappings.

### Deleting a connection

```
DELETE /api/v1/channels/{channel_id}
```

An active connection must be deactivated first. Deleting removes the connection and all its mappings; bookings received through it are kept.

### Actions

The MG Bedbank adapter declares no connection actions — `actions` is empty on the descriptor and on every MG Bedbank connection.

### MG Bedbank settings reference

The full set of connection `settings` for MG Bedbank:

| Setting                    | Description                                                                                                                                                                                                           |
| -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `hotel_id`                 | The MG Bedbank Hotel ID. Required.                                                                                                                                                                                    |
| `send_email_notifications` | When `true`, Channex sends a notification about each booking.                                                                                                                                                         |
| `email`                    | The email address the notifications go to.                                                                                                                                                                            |
| `min_stay_type`            | Which Channex minimum stay restriction is sent to MG Bedbank: `Arrival` (Min Stay Arrival — counted from the arrival date) or `Through` (Min Stay Through — applied to every stayed-through date). Default `Arrival`. |
