{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/the-things-network/json-schema/the-things-network-v3-app-as-downlink-queue-replace-body-schema.json",
  "title": "v3AppAsDownlinkQueueReplaceBody",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/the-things-network-appas-api-openapi.yml#/components/schemas/v3AppAsDownlinkQueueReplaceBody",
  "type": "object",
  "properties": {
    "end_device_ids": {
      "type": "object",
      "properties": {
        "application_ids": {
          "type": "object"
        },
        "dev_eui": {
          "type": "string",
          "format": "string",
          "description": "The LoRaWAN DevEUI."
        },
        "join_eui": {
          "type": "string",
          "format": "string",
          "description": "The LoRaWAN JoinEUI (AppEUI until LoRaWAN 1.0.3 end devices)."
        },
        "dev_addr": {
          "type": "string",
          "format": "string",
          "description": "The LoRaWAN DevAddr."
        }
      }
    },
    "downlinks": {
      "type": "array",
      "items": {
        "type": "object",
        "$ref": "#/$defs/v3ApplicationDownlink"
      }
    }
  },
  "$defs": {
    "ApplicationDownlinkClassBC": {
      "type": "object",
      "properties": {
        "gateways": {
          "type": "array",
          "items": {
            "type": "object",
            "$ref": "#/$defs/v3ClassBCGatewayIdentifiers"
          },
          "description": "Possible gateway identifiers, antenna index, and group index to use for this downlink message.\nThe Network Server selects one of these gateways for downlink, based on connectivity, signal quality, channel utilization and an available slot.\nIf none of the gateways can be selected, the downlink message fails.\nIf empty, a gateway and antenna is selected automatically from the gateways seen in recent uplinks.\nIf group index is set, gateways will be grouped by the index for the Network Server to select one gateway per group."
        },
        "absolute_time": {
          "type": "string",
          "format": "date-time",
          "description": "Absolute time when the downlink message should be transmitted.\nThis requires the gateway to have GPS time synchronization.\nIf the time is in the past or if there is a scheduling conflict, the downlink message fails.\nIf null, the time is selected based on slot availability. This is recommended in class B mode."
        }
      }
    },
    "ApplicationDownlinkConfirmedRetry": {
      "type": "object",
      "properties": {
        "attempt": {
          "type": "integer",
          "format": "int64",
          "description": "The number of attempted confirmed downlink acknowledgements."
        },
        "max_attempts": {
          "type": "integer",
          "format": "int64",
          "description": "The maximum number of confirmed downlink acknowledgement attempts.\nIf null, the Application Server configuration is used instead."
        }
      }
    },
    "lorawanv3GatewayIdentifiers": {
      "type": "object",
      "properties": {
        "gateway_id": {
          "type": "string"
        },
        "eui": {
          "type": "string",
          "format": "string",
          "description": "Secondary identifier, which can only be used in specific requests."
        }
      }
    },
    "lorawanv3Location": {
      "type": "object",
      "properties": {
        "latitude": {
          "type": "number",
          "format": "double",
          "description": "The North–South position (degrees; -90 to +90), where 0 is the equator, North pole is positive, South pole is negative."
        },
        "longitude": {
          "type": "number",
          "format": "double",
          "description": "The East-West position (degrees; -180 to +180), where 0 is the Prime Meridian (Greenwich), East is positive , West is negative."
        },
        "altitude": {
          "type": "integer",
          "format": "int32",
          "description": "The altitude (meters), where 0 is the mean sea level."
        },
        "accuracy": {
          "type": "integer",
          "format": "int32",
          "description": "The accuracy of the location (meters)."
        },
        "source": {
          "$ref": "#/$defs/v3LocationSource",
          "description": "Source of the location information."
        }
      }
    },
    "v3ApplicationDownlink": {
      "type": "object",
      "properties": {
        "session_key_id": {
          "type": "string",
          "format": "byte",
          "description": "Join Server issued identifier for the session keys used by this downlink."
        },
        "f_port": {
          "type": "integer",
          "format": "int64"
        },
        "f_cnt": {
          "type": "integer",
          "format": "int64"
        },
        "frm_payload": {
          "type": "string",
          "format": "byte",
          "description": "The frame payload of the downlink message.\nThe payload is encrypted if the skip_payload_crypto field of the EndDevice\nis true."
        },
        "decoded_payload": {
          "type": "object",
          "description": "The decoded frame payload of the downlink message.\nWhen scheduling downlink with a message processor configured for the end device (see formatters) or application (see default_formatters),\nthis fields acts as input for the downlink encoder, and the output is set to frm_payload.\nWhen reading downlink (listing the queue, downlink message events, etc), this fields acts as output of the downlink decoder, and the input is frm_payload."
        },
        "decoded_payload_warnings": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Warnings generated by the message processor while encoding frm_payload (scheduling downlink) or decoding the frm_payload (reading downlink)."
        },
        "confirmed": {
          "type": "boolean"
        },
        "class_b_c": {
          "$ref": "#/$defs/ApplicationDownlinkClassBC",
          "description": "Optional gateway and timing information for class B and C.\nIf set, this downlink message will only be transmitted as class B or C downlink.\nIf not set, this downlink message may be transmitted in class A, B and C."
        },
        "priority": {
          "$ref": "#/$defs/v3TxSchedulePriority",
          "description": "Priority for scheduling the downlink message."
        },
        "correlation_ids": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "confirmed_retry": {
          "$ref": "#/$defs/ApplicationDownlinkConfirmedRetry"
        },
        "locations": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/lorawanv3Location"
          },
          "description": "End device location metadata, set by the Application Server while handling the message."
        },
        "version_ids": {
          "$ref": "#/$defs/v3EndDeviceVersionIdentifiers",
          "description": "End device version identifiers, set by the Application Server while handling the message."
        },
        "network_ids": {
          "$ref": "#/$defs/v3NetworkIdentifiers",
          "description": "Network identifiers, set by the Network Server that handles the message."
        },
        "attributes": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          },
          "description": "Attributes for devices, set by the Application Server while handling the message."
        }
      }
    },
    "v3ClassBCGatewayIdentifiers": {
      "type": "object",
      "properties": {
        "gateway_ids": {
          "$ref": "#/$defs/lorawanv3GatewayIdentifiers"
        },
        "antenna_index": {
          "type": "integer",
          "format": "int64"
        },
        "group_index": {
          "type": "integer",
          "format": "int64"
        }
      }
    },
    "v3EndDeviceVersionIdentifiers": {
      "type": "object",
      "properties": {
        "brand_id": {
          "type": "string"
        },
        "model_id": {
          "type": "string"
        },
        "hardware_version": {
          "type": "string"
        },
        "firmware_version": {
          "type": "string"
        },
        "band_id": {
          "type": "string"
        }
      },
      "description": "Identifies an end device model with version information."
    },
    "v3LocationSource": {
      "type": "string",
      "enum": [
        "SOURCE_UNKNOWN",
        "SOURCE_GPS",
        "SOURCE_REGISTRY",
        "SOURCE_IP_GEOLOCATION",
        "SOURCE_WIFI_RSSI_GEOLOCATION",
        "SOURCE_BT_RSSI_GEOLOCATION",
        "SOURCE_LORA_RSSI_GEOLOCATION",
        "SOURCE_LORA_TDOA_GEOLOCATION",
        "SOURCE_COMBINED_GEOLOCATION"
      ],
      "default": "SOURCE_UNKNOWN",
      "description": " - SOURCE_UNKNOWN: The source of the location is not known or not set.\n - SOURCE_GPS: The location is determined by GPS.\n - SOURCE_REGISTRY: The location is set in and updated from a registry.\n - SOURCE_IP_GEOLOCATION: The location is estimated with IP geolocation.\n - SOURCE_WIFI_RSSI_GEOLOCATION: The location is estimated with WiFi RSSI geolocation.\n - SOURCE_BT_RSSI_GEOLOCATION: The location is estimated with BT/BLE RSSI geolocation.\n - SOURCE_LORA_RSSI_GEOLOCATION: The location is estimated with LoRa RSSI geolocation.\n - SOURCE_LORA_TDOA_GEOLOCATION: The location is estimated with LoRa TDOA geolocation.\n - SOURCE_COMBINED_GEOLOCATION: The location is estimated by a combination of geolocation sources.\n\nMore estimation methods can be added."
    },
    "v3NetworkIdentifiers": {
      "type": "object",
      "properties": {
        "net_id": {
          "type": "string",
          "format": "string",
          "description": "LoRa Alliance NetID."
        },
        "ns_id": {
          "type": "string",
          "format": "string",
          "description": "LoRaWAN NSID (EUI-64) that uniquely identifies the Network Server instance."
        },
        "tenant_id": {
          "type": "string",
          "description": "Optional tenant identifier for multi-tenant deployments."
        },
        "cluster_id": {
          "type": "string",
          "description": "Cluster identifier of the Network Server."
        },
        "cluster_address": {
          "type": "string",
          "description": "Cluster address of the Network Server."
        },
        "tenant_address": {
          "type": "string",
          "description": "Optional tenant address for multi-tenant deployments."
        }
      },
      "description": "Identifies a Network Server."
    },
    "v3TxSchedulePriority": {
      "type": "string",
      "enum": [
        "LOWEST",
        "LOW",
        "BELOW_NORMAL",
        "NORMAL",
        "ABOVE_NORMAL",
        "HIGH",
        "HIGHEST"
      ],
      "default": "LOWEST"
    }
  }
}