{
  "openapi": "3.1.0",
  "info": {
    "title": "Pellroll",
    "version": "0.1.0",
    "description": "Who UK central government paid, how much and when: monthly spend files joined by supplier and Companies House number."
  },
  "servers": [
    {
      "url": "https://pellroll.bulkhead.solutions"
    }
  ],
  "security": [
    {
      "bearer": []
    },
    {}
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    }
  },
  "paths": {
    "/v1/tools/find_supplier": {
      "post": {
        "operationId": "find_supplier",
        "summary": "Find a supplier in the ledger",
        "description": "Finds suppliers paid by UK central government by name or Companies House number, and returns each one's supplier_id, Companies House number and status where matched, how the match was made, the names departments published it under, its total and number of payments since April 2024, first and last payment dates, and the five departments that paid it most. Call it first, to turn a company name into the supplier_id the other tools take, or to check whether a company has any published central government payments at all. Results are ranked by name match, then by total paid; at most 25. It does not cover local councils, NHS trusts or payments under £25,000, and it never returns names that may belong to a private individual, so a sole trader is not found.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "query"
                ],
                "properties": {
                  "query": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 200,
                    "description": "Supplier name or part of it (Serco, Capita Business Services Ltd), or a Companies House number (00242246)."
                  },
                  "limit": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 25,
                    "description": "Maximum matches, default 10."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "429": {
            "description": "Limit reached"
          }
        }
      }
    },
    "/v1/tools/supplier_spend": {
      "post": {
        "operationId": "supplier_spend",
        "summary": "Total paid to a supplier",
        "description": "Totals what UK central government paid one supplier over a period, grouped by paying department (default), month, financial year or expense type, with the first and last payment, the source files that carry the most value (URL, title and publication page), and coverage notes when a department has not yet published the end of the period. Ends with summary, one sentence to quote. Call it for questions like how much the Home Office paid Serco in 2025-26 or how a supplier's central government revenue moved by month. Use supplier_payments for the individual lines. These are payments as published (invoices, grants, credit notes), not contract values, and they include VAT where the department published gross amounts.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "supplier"
                ],
                "properties": {
                  "supplier": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "description": "A supplier_id from find_supplier (a Companies House number such as 00242246, or an id such as n-network-rail), a Companies House number, or the supplier's exact name."
                  },
                  "from": {
                    "type": "string",
                    "maxLength": 10,
                    "description": "Start of the period, YYYY-MM-DD, YYYY-MM or YYYY. The ledger starts on 2024-04-01."
                  },
                  "to": {
                    "type": "string",
                    "maxLength": 10,
                    "description": "End of the period, YYYY-MM-DD, YYYY-MM or YYYY, inclusive. Defaults to the newest payment."
                  },
                  "financial_year": {
                    "type": "string",
                    "maxLength": 12,
                    "description": "UK financial year instead of from and to, for example 2025-26 (1 April 2025 to 31 March 2026)."
                  },
                  "group_by": {
                    "type": "string",
                    "enum": [
                      "publisher",
                      "month",
                      "financial_year",
                      "expense_type"
                    ],
                    "description": "How to group the total: publisher (default), month, financial_year or expense_type."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "429": {
            "description": "Limit reached"
          }
        }
      }
    },
    "/v1/tools/supplier_payments": {
      "post": {
        "operationId": "supplier_payments",
        "summary": "Payment lines to a supplier",
        "description": "Lists the individual published payments to one supplier, newest first: date, amount in pounds, paying department and entity, expense type and area, transaction number, and the exact source (file URL, sheet and row number, publication page) so each line can be checked. Filter by period, department and a minimum amount; page with next_cursor while has_more is true (default 25, at most 100 a page). Call it to show or cite specific payments, or to check a single invoice. Use supplier_spend for totals. Free-text descriptions and supplier postcodes from the files are not served; open the source row to read them.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "supplier"
                ],
                "properties": {
                  "supplier": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "description": "A supplier_id from find_supplier (a Companies House number such as 00242246, or an id such as n-network-rail), a Companies House number, or the supplier's exact name."
                  },
                  "from": {
                    "type": "string",
                    "maxLength": 10,
                    "description": "Start of the period, YYYY-MM-DD, YYYY-MM or YYYY. The ledger starts on 2024-04-01."
                  },
                  "to": {
                    "type": "string",
                    "maxLength": 10,
                    "description": "End of the period, YYYY-MM-DD, YYYY-MM or YYYY, inclusive. Defaults to the newest payment."
                  },
                  "financial_year": {
                    "type": "string",
                    "maxLength": 12,
                    "description": "UK financial year instead of from and to, for example 2025-26 (1 April 2025 to 31 March 2026)."
                  },
                  "publisher": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 120,
                    "description": "Paying department: a short code (HMRC, MOD, DWP, HO, MOJ, DfE, DfT, DHSC, CO, HMT, DBT, DESNZ, Defra, DSIT, DCMS, FCDO, MHCLG, HMLR, UKEF, CMA, AGO, NIO, SO, OAG) or its GOV.UK slug."
                  },
                  "min_gbp": {
                    "type": "number",
                    "minimum": 0,
                    "description": "Only payments of at least this many pounds."
                  },
                  "limit": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100,
                    "description": "Payments per page, default 25, at most 100."
                  },
                  "cursor": {
                    "type": "string",
                    "maxLength": 20,
                    "description": "next_cursor from the previous call."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "429": {
            "description": "Limit reached"
          }
        }
      }
    },
    "/v1/tools/buyer_suppliers": {
      "post": {
        "operationId": "buyer_suppliers",
        "summary": "Whom a department pays most",
        "description": "Ranks the suppliers one UK central government department paid most over a period, by whole months: rank, supplier_id, name, Companies House number, total, payments and share of the department's published spend, plus the total it paid to names that are not shown (possible individuals, redactions, placeholders). Call it to size an account, find a department's largest suppliers or competitors, or see where a buyer's money goes. Pass companies_only to rank only suppliers matched to Companies House, which leaves out grants to councils and public bodies. At most 100 suppliers.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "publisher"
                ],
                "properties": {
                  "publisher": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 120,
                    "description": "Paying department: a short code (HMRC, MOD, DWP, HO, MOJ, DfE, DfT, DHSC, CO, HMT, DBT, DESNZ, Defra, DSIT, DCMS, FCDO, MHCLG, HMLR, UKEF, CMA, AGO, NIO, SO, OAG) or its GOV.UK slug."
                  },
                  "from": {
                    "type": "string",
                    "maxLength": 10,
                    "description": "Start of the period, YYYY-MM-DD, YYYY-MM or YYYY. The ledger starts on 2024-04-01."
                  },
                  "to": {
                    "type": "string",
                    "maxLength": 10,
                    "description": "End of the period, YYYY-MM-DD, YYYY-MM or YYYY, inclusive. Defaults to the newest payment."
                  },
                  "financial_year": {
                    "type": "string",
                    "maxLength": 12,
                    "description": "UK financial year instead of from and to, for example 2025-26 (1 April 2025 to 31 March 2026)."
                  },
                  "limit": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100,
                    "description": "How many suppliers, default 20."
                  },
                  "companies_only": {
                    "type": "boolean",
                    "description": "Only suppliers matched to a Companies House company; default false."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "429": {
            "description": "Limit reached"
          }
        }
      }
    },
    "/v1/tools/ledger_coverage": {
      "post": {
        "operationId": "ledger_coverage",
        "summary": "What the ledger covers",
        "description": "Shows which departments are in the ledger, how many files and payments each has, its first and newest payment, and months missing since April 2024; with publisher, also the months with totals and the files read (including nil returns). Call it before telling a user that a payment does not exist, or to explain why a recent month is empty: departments publish one to three months late, and some stopped or have gaps (FCDO's last published month is January 2025). It costs nothing to call and does not count supplier data.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "publisher": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 120,
                    "description": "Paying department: a short code (HMRC, MOD, DWP, HO, MOJ, DfE, DfT, DHSC, CO, HMT, DBT, DESNZ, Defra, DSIT, DCMS, FCDO, MHCLG, HMLR, UKEF, CMA, AGO, NIO, SO, OAG) or its GOV.UK slug."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "429": {
            "description": "Limit reached"
          }
        }
      }
    },
    "/v1/tools/changes_since": {
      "post": {
        "operationId": "changes_since",
        "summary": "Files added since a date",
        "description": "Lists the spend files Pellroll first read after a date, newest first, with department, the month each covers, payments added and the file URL. Filter by department. Call it once a week to learn which departments have published new months, then query the suppliers you track with supplier_payments. It lists files, not individual changes to rows; a republished file whose rows repeat an earlier one adds nothing.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "since"
                ],
                "properties": {
                  "since": {
                    "type": "string",
                    "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
                    "description": "Date YYYY-MM-DD: files first read after this day are listed."
                  },
                  "publisher": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 120,
                    "description": "Paying department: a short code (HMRC, MOD, DWP, HO, MOJ, DfE, DfT, DHSC, CO, HMT, DBT, DESNZ, Defra, DSIT, DCMS, FCDO, MHCLG, HMLR, UKEF, CMA, AGO, NIO, SO, OAG) or its GOV.UK slug."
                  },
                  "limit": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 200,
                    "description": "Maximum files, default 50."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "429": {
            "description": "Limit reached"
          }
        }
      }
    }
  }
}
