{
  "$schema": "../rpc-schema-draft.json",
  "type": "object",
  "rpc": "listpays",
  "title": "Command for querying payment status",
  "description": [
    "The **listpays** RPC command gets the status of all *pay* commands (by combining results from listsendpays which lists every payment part), or a single one if either *bolt11* or *payment_hash* was specified."
  ],
  "categories": [
    "readonly"
  ],
  "request": {
    "required": [],
    "additionalProperties": false,
    "properties": {
      "bolt11": {
        "type": "string",
        "description": [
          "Bolt11 string to get the payment details."
        ]
      },
      "payment_hash": {
        "type": "hash",
        "description": [
          "Payment hash to get the payment details."
        ]
      },
      "status": {
        "type": "string",
        "description": [
          "To filter the payment by status."
        ],
        "enum": [
          "pending",
          "complete",
          "failed"
        ]
      },
      "index": {
        "type": "string",
        "added": "v24.11",
        "enum": [
          "created",
          "updated"
        ],
        "description": [
          "If neither *in_channel* nor *out_channel* is specified, it controls ordering, by `created` or `updated`."
        ]
      },
      "start": {
        "type": "u64",
        "added": "v24.11",
        "description": [
          "If `index` is specified, `start` may be specified to start from that value, which is generally returned from lightning-wait(7).",
          "NOTE: if this is used, `amount_sent_msat` and `number_of_parts` fields may be lower than expected, as not all payment parts will be considered"
        ]
      },
      "limit": {
        "type": "u32",
        "added": "v24.11",
        "description": [
          "If `index` is specified, `limit` can be used to specify the maximum number of entries to return.",
          "NOTE: if this is used, `amount_sent_msat` and `number_of_parts` fields may be lower than expected, as not all payment parts will be considered",
          "NOTE: the actual number returned may be less than the limit, as individual payment parts are combined together"
        ]
      }
    }
  },
  "response": {
    "required": [
      "pays"
    ],
    "additionalProperties": false,
    "properties": {
      "pays": {
        "type": "array",
        "items": {
          "type": "object",
          "additionalProperties": true,
          "required": [
            "payment_hash",
            "status",
            "created_at",
            "created_index"
          ],
          "properties": {
            "payment_hash": {
              "type": "hash",
              "description": [
                "The hash of the *payment_preimage* which will prove payment."
              ]
            },
            "status": {
              "type": "string",
              "enum": [
                "pending",
                "failed",
                "complete"
              ],
              "description": [
                "Status of the payment."
              ]
            },
            "destination": {
              "type": "pubkey",
              "description": [
                "The final destination of the payment if known."
              ]
            },
            "created_at": {
              "type": "u64",
              "description": [
                "The UNIX timestamp showing when this payment was initiated."
              ]
            },
            "completed_at": {
              "type": "u64",
              "description": [
                "The UNIX timestamp showing when this payment was completed."
              ]
            },
            "label": {
              "type": "string",
              "description": [
                "The label, if given to sendpay."
              ]
            },
            "bolt11": {
              "type": "string",
              "description": [
                "The bolt11 string (if pay supplied one)."
              ]
            },
            "description": {
              "type": "string",
              "description": [
                "The description matching the bolt11 description hash (if pay supplied one)."
              ]
            },
            "bolt12": {
              "type": "string",
              "description": [
                "The bolt12 string (if supplied for pay)."
              ]
            },
            "created_index": {
              "type": "u64",
              "added": "v24.11",
              "description": [
                "1-based index indicating order this payment was created in."
              ]
            },
            "updated_index": {
              "type": "u64",
              "added": "v24.11",
              "description": [
                "1-based index indicating order this payment was changed (only present if it has changed since creation)."
              ]
            }
          },
          "allOf": [
            {
              "if": {
                "additionalProperties": true,
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "complete"
                    ]
                  }
                }
              },
              "then": {
                "additionalProperties": false,
                "required": [
                  "amount_sent_msat",
                  "preimage"
                ],
                "properties": {
                  "created_index": {},
                  "updated_index": {},
                  "payment_hash": {},
                  "status": {},
                  "destination": {},
                  "created_at": {},
                  "completed_at": {},
                  "label": {},
                  "bolt11": {},
                  "description": {},
                  "bolt12": {},
                  "amount_msat": {
                    "type": "msat",
                    "description": [
                      "The amount of millisatoshi we intended to send to the destination. This can only be missing in the case of someone manually calling sendonion without the `amount_msat` parameter (which no plugin currently does)."
                    ]
                  },
                  "amount_sent_msat": {
                    "type": "msat",
                    "description": [
                      "The amount of millisatoshi we sent in order to pay (may include fees and not match amount_msat)."
                    ]
                  },
                  "preimage": {
                    "type": "secret",
                    "description": [
                      "Proof of payment."
                    ]
                  },
                  "number_of_parts": {
                    "type": "u64",
                    "description": [
                      "The number of parts for a successful payment (only if more than one)."
                    ]
                  }
                }
              }
            },
            {
              "if": {
                "additionalProperties": true,
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "failed"
                    ]
                  }
                }
              },
              "then": {
                "additionalProperties": false,
                "required": [
                  "amount_sent_msat"
                ],
                "properties": {
                  "created_index": {},
                  "updated_index": {},
                  "payment_hash": {},
                  "status": {},
                  "destination": {},
                  "created_at": {},
                  "label": {},
                  "bolt11": {},
                  "description": {},
                  "bolt12": {},
                  "amount_sent_msat": {},
                  "erroronion": {
                    "type": "hex",
                    "description": [
                      "The error onion returned on failure, if any."
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    },
    "post_return_value_notes": [
      "The returned array is ordered by increasing **created_at** fields."
    ]
  },
  "author": [
    "Rusty Russell [rusty@rustcorp.com.au](mailto:rusty@rustcorp.com.au) is mainly responsible."
  ],
  "see_also": [
    "lightning-pay(7)",
    "lightning-paystatus(7)",
    "lightning-listsendpays(7)"
  ],
  "resources": [
    "Main web site: [https://github.com/ElementsProject/lightning](https://github.com/ElementsProject/lightning)"
  ],
  "examples": [
    {
      "request": {
        "id": "example:listpays#1",
        "method": "listpays",
        "params": {
          "bolt11": "lnbcrt100n1pnt2bolt11invl032000000000bolt11invl032000000000bolt11invl032000000000bolt11invl032000000000bolt11invl032000000000bolt11invl032000000000bolt11invl032000000000bolt11invl032000000000bolt11invl032000000000bolt11invl032000000000"
        }
      },
      "response": {
        "pays": []
      }
    },
    {
      "request": {
        "id": "example:listpays#2",
        "method": "listpays",
        "params": {}
      },
      "response": {
        "pays": []
      }
    }
  ]
}
