{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/lune/json-schema/lune-create-order-by-estimate-request-schema.json",
  "title": "CreateOrderByEstimateRequest",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/lune-orders-api-openapi.yml#/components/schemas/CreateOrderByEstimateRequest",
  "type": "object",
  "required": [
    "estimate_id"
  ],
  "properties": {
    "estimate_id": {
      "type": "string",
      "description": "The emission calculation unique identifier"
    },
    "idempotency_key": {
      "type": "string",
      "maxLength": 100,
      "description": "Account-unique identifier provided by the client.\n\n`idempotency_key` has two purposes:\n1. Clients can use `idempotency_key` to prevent duplicate orders.\n2. Clients can use `idempotency_key` to reconcile orders with other entities on their system.\n\nIf an order with the same `idempotency_key` already exists, the API returns\nHTTP 409 Conflict with error code `order_idempotency_already_exists`. To\nretrieve the existing order, use the\n`GET /v1/orders/by-idempotency-key/{idempotency_key}` endpoint.\n"
    },
    "bundle_selection": {
      "$ref": "#/$defs/BundleSelectionRequest"
    },
    "metadata": {
      "$ref": "#/$defs/Metadata",
      "default": {}
    },
    "quantity_trunc": {
      "$ref": "#/$defs/QuantityTrunc"
    }
  },
  "$defs": {
    "BundlePercentageRequest": {
      "type": "object",
      "description": "Maps a bundle id to an allocation ratio",
      "required": [
        "bundle_id"
      ],
      "properties": {
        "bundle_id": {
          "type": "string",
          "description": "The bundle's unique identifier"
        },
        "percentage": {
          "oneOf": [
            {
              "type": "integer",
              "x-lune-name": "Selection percentage as integer",
              "description": "Selection percentage"
            },
            {
              "type": "string",
              "pattern": "^[0-9]+(\\.\\d{1,2})?$",
              "x-lune-name": "Selection percentage in decimals",
              "description": "Selection percentage in decimals"
            }
          ]
        }
      }
    },
    "BundleSelectionRequest": {
      "type": "array",
      "description": "Bundle selection percentages.\n\nThe sum of all percentages must equal 100.\n\nIf not specified, the preconfigured allocation ratios are going to be used.\n\nIf, for each selection, `percentage` is not provided, the selection is divided equally (best effort) between bundles. `percentage` must be provided for all or none of the bundles.\n",
      "items": {
        "$ref": "#/$defs/BundlePercentageRequest"
      }
    },
    "MassUnit": {
      "x-lune-name": "Mass",
      "type": "string",
      "description": "Unit, `t` for tonne, `kg` for kilogram, `g` for gram, `lbs` for pound",
      "enum": [
        "g",
        "kg",
        "t",
        "lbs"
      ]
    },
    "Metadata": {
      "description": "An arbitrary dictionary (key-value pairs) to store application-specific information.\n\nLune doesn't use this information for order processing. Its purpose is for the API\nclients to be able to attach arbitrary information (to an order for example) and\nthen retrieve it.\n",
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    },
    "QuantityTrunc": {
      "description": "Selects to which precision to truncate quantities specific to carbon offsetting.",
      "allOf": [
        {
          "$ref": "#/$defs/MassUnit"
        }
      ]
    }
  }
}