> ## Documentation Index
> Fetch the complete documentation index at: https://api-docs.bienport.com/llms.txt
> Use this file to discover all available pages before exploring further.

# (Internal) API Gateway ↔ Communication Backend

> AMQP-based internal command/response flows between the Api Gateway and Communication Backend service.

<Note>
  This is a private API and works internally!
</Note>

<Info>
  **Scope:** This section documents the **internal** AMQP exchanges used by the Api Gateway to query/maintain system state and enrich external MQTT command flows.
  These messages are **not** exposed to mobile/web clients directly.
</Info>

## Transport & Routing

* **Protocol:** AMQP
* **Request Queue (gateway → backend):** `resource.commands`
* **Response Queue (backend → gateway):** `bimetri.apiservice.<api-uniqueue-id>`
* **Correlation:** `correlationId` is mandatory. Gateway sets it; backend mirrors it in replies.
* **Delivery:** at‑least‑once; consumers must be idempotent.
* **Delivered via routing key:** `bimetri.apiservice.<app-unique-id>`

<Warning>
  Internal payloads may include identifiers not present in external APIs (e.g., `resourceId`, `sensorId`, `controllerId`). Treat them as **opaque** outside the backend boundary.
</Warning>

<Info>
  Note: Keys in requests are unique to each request and are used to queue requests.
</Info>

# Commands

Below are common internal commands the Api Gateway uses to hydrate caches, resolve routing, and enrich MQTT command/notification paths.

## 1) Get Sensors Command

> Returns the list of sensors discovered on the panel (zone → sensor mapping, with metadata).

### Request

```json theme={null}
{
  "messageType": "commandMessage",
  "appId": "replace-with-your-app’s-unique-id",
  "brand": "EBS",
  "command": "getSensors",
  "correlationId": "1",
  "parameters": {
    "resourceId": 50,
    "key": "random-UUID"
  }
}
```

### Success Response

```json theme={null}
{
  "messageType": "commandResponse",
  "correlationId": "1",
  "result": "success",
  "reason": "send",
  "data": {
    "command": "getSensors",
    "resourceId": 50,
    "key": "random-UUID",
    "sensors": [
      {
        "zone": "10",
        "hardwareSerial": "350001938",
        "sensorId": 40,
        "sensorName": "PIRCAM-30 Kameralı Wifi Hareket Sensörü",
        "sensorType": "Digital"
      },
      {
        "zone": "12",
        "hardwareSerial": "340004502",
        "sensorId": 39,
        "sensorName": "PIR-30 Kablosuz Hareket Dedektörü",
        "sensorType": "Digital"
      }
      {
        "zone": "9",
        "hardwareSerial": "830002331",
        "sensorName": "Not defined or not a sensor",
        "sensorType": "Unknown"
      }
    ]
  }
}
```

## 2) Get Controllers Command

> Returns output controllers per partition (e.g., relays / DOs) that can be driven by the platform.

### Request

```json theme={null}
{
  "messageType": "commandMessage",
  "appId": "replace-with-your-app’s-unique-id",
  "brand": "EBS",
  "command": "getControllers",
  "correlationId": "1",
  "parameters": {
    "resourceId": 50,
    "pinCode": "AES-256 encrypted pin code",
    "key": "random-UUID"
    
  }
}
```

### Success Response

```json theme={null}
{
    "messageType": "commandResponse",
    "correlationId": "344",
    "result": "success",
    "reason": "send",
    "data": {
        "command": "getControllers",
        "resourceId": 370,
        "key": "1105a80d-df06-4dc0-8970-ff4c6c766dc7",
        "partitionControllers": [
            {
                "partitionNo": 1,
                "controllers": [
                    {
                        "controllerId": 34,
                        "outputPort": 1,
                        "controllerName": "Röle",
                        "controllerType": "Digital"
                    }
                ]
            },
            {
                "partitionNo": 2,
                "controllers": [
                    {
                        "controllerId": 34,
                        "outputPort": 2,
                        "controllerName": "Röle",
                        "controllerType": "Digital"
                    }
                ]
            }
        ]
    }
}
```

## 3) Get Partition Zone Command

> Returns zones (sensors) grouped by partition.

### Request

```json theme={null}
{
  "messageType": "commandMessage",
  "appId": "replace-with-your-app’s-unique-id",
  "brand": "EBS",
  "command": "getPartitionZone",
  "correlationId": "1",
  "parameters": {
    "resourceId": 1,
    "pinCode": "AES-256 encrypted pin code",
    "key": "random-UUID"
  }
}
```

### Success Response

```json theme={null}
{
    "messageType": "commandResponse",
    "correlationId": "346",
    "result": "success",
    "reason": "send",
    "data": {
        "resourceId": 370,
        "command": "getPartitionZone",
        "key": "1105a80d-df06-4dc0-8970-ff4c6c766dc7",
        "partitionSensors": [
            {
                "partitionNo": 1,
                "zones": [
                    {
                        "sensorId": 114,
                        "zoneNumber": 1,
                        "sensorName": "Kablolu Sensör",
                        "sensorType": "Dijital"
                    }
                ]
            },
            {
                "partitionNo": 2,
                "zones": [
                    {
                        "sensorId": 114,
                        "zoneNumber": 2,
                        "sensorName": "Kablolu Sensör",
                        "sensorType": "Dijital"
                    }
                ]
            }
        ]
    }
}
```

## 4) Get Partition Name Command

> Returns the human-friendly name for a given partition number.

### Request

```json theme={null}
{
  "messageType": "commandMessage",
  "appId": "replace-with-your-app’s-unique-id",
  "brand": "EBS",
  "command": "getPartitionName",
  "correlationId": "1",
  "parameters": {
    "resourceId": 195,
    "partitionNo": 1,
    "key": "random-UUID"
  }
}
```

### Success Response

```json theme={null}
{
  "messageType": "commandResponse",
  "correlationId": "1",
  "result": "success",
  "reason": "send",
  "data": {
    "partitionNo": "1",
    "partitionName": "Partition 1",
    "resourceId": 195,
    "key": "random-UUID",
  }
}
```
