Phoenix Wallet

Lots

API endpoints for querying and managing value tranches

Lots are individual tranches of value within a wallet. Each lot tracks its own balance, attributes, expiration, and restrictions. The system automatically manages lots during credits, transfers, and debits.

Get Lot

Retrieve details of a specific lot.

GET /lots/{{LOT_ID}}

Path Parameters

ParameterTypeDescription
lot_idstringThe lot ID (e.g., lot_xyz789abc123)

Example Request

curl -X GET {{BASE_URL}}/lots/{{LOT_ID}} \
  -H "Authorization: Bearer {{API_KEY}}"

Example Response

{
  "data": {
    "id": "lot_xyz789abc123",
    "wallet_id": "wal_abc123def456",
    "asset": "POINTS",
    "initial_amount": "500.00",
    "current_amount": "350.00",
    "reserved_amount": "50.00",
    "available_amount": "300.00",
    "status": "active",
    "expires_at": "2024-12-31T23:59:59Z",
    "attributes": {
      "source": "promotion",
      "campaign": "winter_2024",
      "tier_multiplier": 1.5
    },
    "restrictions": [
      {
        "type": "category",
        "allowed": ["merchandise", "food"]
      }
    ],
    "source": {
      "type": "credit",
      "id": "crd_xyz789abc123",
      "reference": "purchase_order_789"
    },
    "created_at": "2024-01-15T10:30:00Z",
    "updated_at": "2024-01-20T14:00:00Z"
  }
}

Error Codes

CodeDescription
LOT_NOT_FOUNDNo lot exists with this ID

List Wallet Lots

Retrieve all lots for a specific wallet.

GET /wallets/{{WALLET_ID}}/lots

Path Parameters

ParameterTypeDescription
wallet_idstringThe wallet ID

Query Parameters

ParameterTypeDefaultDescription
limitinteger20Number of results (max 100)
cursorstring-Pagination cursor
assetstring-Filter by asset type
statusstring-Filter by status: active, depleted, expired
has_balanceboolean-Filter to lots with remaining balance
expiring_beforestring-Filter lots expiring before date (ISO 8601)
attributestring-Filter by attribute (format: key:value)

Example Request

curl -X GET "{{BASE_URL}}/wallets/{{WALLET_ID}}/lots?status=active&has_balance=true&asset=POINTS" \
  -H "Authorization: Bearer {{API_KEY}}"

Example Response

{
  "data": [
    {
      "id": "lot_xyz789abc123",
      "wallet_id": "wal_abc123def456",
      "asset": "POINTS",
      "current_amount": "350.00",
      "reserved_amount": "50.00",
      "available_amount": "300.00",
      "status": "active",
      "expires_at": "2024-12-31T23:59:59Z",
      "attributes": {
        "source": "promotion",
        "campaign": "winter_2024"
      },
      "created_at": "2024-01-15T10:30:00Z"
    },
    {
      "id": "lot_abc456def789",
      "wallet_id": "wal_abc123def456",
      "asset": "POINTS",
      "current_amount": "200.00",
      "reserved_amount": "0.00",
      "available_amount": "200.00",
      "status": "active",
      "expires_at": null,
      "attributes": {
        "source": "purchase"
      },
      "created_at": "2024-01-10T08:00:00Z"
    }
  ],
  "pagination": {
    "has_more": false,
    "next_cursor": null
  }
}

Get Lot History

Retrieve the transaction history for a specific lot.

GET /lots/{{LOT_ID}}/history

Path Parameters

ParameterTypeDescription
lot_idstringThe lot ID

Query Parameters

ParameterTypeDefaultDescription
limitinteger20Number of results (max 100)
cursorstring-Pagination cursor

Example Request

curl -X GET "{{BASE_URL}}/lots/{{LOT_ID}}/history?limit=10" \
  -H "Authorization: Bearer {{API_KEY}}"

Example Response

{
  "data": [
    {
      "id": "evt_001",
      "type": "lot.created",
      "amount": "500.00",
      "balance_after": "500.00",
      "source": {
        "type": "credit",
        "id": "crd_xyz789abc123"
      },
      "created_at": "2024-01-15T10:30:00Z"
    },
    {
      "id": "evt_002",
      "type": "lot.reserved",
      "amount": "-100.00",
      "balance_after": "400.00",
      "source": {
        "type": "reservation",
        "id": "rsv_abc123def456"
      },
      "created_at": "2024-01-16T14:00:00Z"
    },
    {
      "id": "evt_003",
      "type": "lot.debited",
      "amount": "-50.00",
      "balance_after": "350.00",
      "source": {
        "type": "transfer",
        "id": "txf_lmn123opq456"
      },
      "created_at": "2024-01-17T09:00:00Z"
    }
  ],
  "pagination": {
    "has_more": false,
    "next_cursor": null
  }
}

Update Lot Attributes

Modify the attributes of a lot. This does not affect the lot's balance.

PATCH /lots/{{LOT_ID}}

Path Parameters

ParameterTypeDescription
lot_idstringThe lot ID

Request Body

FieldTypeRequiredDescription
attributesobjectNoMerge with existing attributes (set value to null to remove)
restrictionsarrayNoReplace all restrictions

Example Request

curl -X PATCH {{BASE_URL}}/lots/{{LOT_ID}} \
  -H "Authorization: Bearer {{API_KEY}}" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: {{IDEMPOTENCY_KEY}}" \
  -d '{
    "attributes": {
      "tier_multiplier": 2.0,
      "old_attribute": null
    }
  }'

Example Response

{
  "data": {
    "id": "lot_xyz789abc123",
    "wallet_id": "wal_abc123def456",
    "asset": "POINTS",
    "current_amount": "350.00",
    "status": "active",
    "attributes": {
      "source": "promotion",
      "campaign": "winter_2024",
      "tier_multiplier": 2.0
    },
    "updated_at": "2024-01-20T15:00:00Z"
  }
}

Error Codes

CodeDescription
LOT_NOT_FOUNDNo lot exists with this ID
LOT_IMMUTABLELot cannot be modified (e.g., depleted or expired)

Expire Lot

Manually expire a lot before its scheduled expiration date.

POST /lots/{{LOT_ID}}/expire

Path Parameters

ParameterTypeDescription
lot_idstringThe lot ID

Request Body

FieldTypeRequiredDescription
reasonstringNoReason for manual expiration

Example Request

curl -X POST {{BASE_URL}}/lots/{{LOT_ID}}/expire \
  -H "Authorization: Bearer {{API_KEY}}" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: {{IDEMPOTENCY_KEY}}" \
  -d '{
    "reason": "Promotional campaign ended early"
  }'

Example Response

{
  "data": {
    "id": "lot_xyz789abc123",
    "wallet_id": "wal_abc123def456",
    "asset": "POINTS",
    "current_amount": "350.00",
    "expired_amount": "350.00",
    "status": "expired",
    "expiration_reason": "Promotional campaign ended early",
    "expires_at": "2024-12-31T23:59:59Z",
    "expired_at": "2024-01-20T15:00:00Z"
  }
}

Error Codes

CodeDescription
LOT_NOT_FOUNDNo lot exists with this ID
LOT_ALREADY_EXPIREDLot is already expired
LOT_HAS_RESERVATIONSCannot expire lot with active reservations

Get Expiring Lots Summary

Get a summary of lots expiring within a time range.

GET /wallets/{{WALLET_ID}}/lots/expiring

Path Parameters

ParameterTypeDescription
wallet_idstringThe wallet ID

Query Parameters

ParameterTypeDefaultDescription
daysinteger30Number of days to look ahead
assetstring-Filter by asset type

Example Request

curl -X GET "{{BASE_URL}}/wallets/{{WALLET_ID}}/lots/expiring?days=7&asset=POINTS" \
  -H "Authorization: Bearer {{API_KEY}}"

Example Response

{
  "data": {
    "wallet_id": "wal_abc123def456",
    "period": {
      "from": "2024-01-20T00:00:00Z",
      "to": "2024-01-27T00:00:00Z"
    },
    "summary": [
      {
        "asset": "POINTS",
        "total_expiring": "750.00",
        "lot_count": 3
      }
    ],
    "lots": [
      {
        "id": "lot_xyz789abc123",
        "asset": "POINTS",
        "available_amount": "300.00",
        "expires_at": "2024-01-22T23:59:59Z"
      },
      {
        "id": "lot_abc456def789",
        "asset": "POINTS",
        "available_amount": "250.00",
        "expires_at": "2024-01-25T23:59:59Z"
      },
      {
        "id": "lot_def789ghi012",
        "asset": "POINTS",
        "available_amount": "200.00",
        "expires_at": "2024-01-26T23:59:59Z"
      }
    ]
  }
}

Lot Statuses

StatusDescription
activeLot has remaining balance and is not expired
depletedLot balance has been fully used
expiredLot has passed its expiration date

Lot Event Types

Event TypeDescription
lot.createdLot was created (via credit)
lot.reservedFunds were reserved from the lot
lot.releasedReserved funds were released
lot.debitedFunds were debited (transfer or commit)
lot.expiredLot expired (automatic or manual)
lot.attributes_updatedLot attributes were modified