diff --git a/openapi.yaml b/openapi.yaml index d24e58e..6315ad2 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -21516,6 +21516,92 @@ paths: "404": $ref: '#/components/responses/NotFound' + /organisations/{organisation_id}/household_counts: + parameters: + - $ref: '#/components/parameters/OrganisationId' + get: + tags: [Beneficiaries] + summary: Count the households an Organisation's Contacts are in + description: | + What the households panel on Manage Contacts shows: how many households (families) the + Organisation's Contacts are in, and what those households are made up of. A household is a + group of Contacts linked, directly or through other Contacts, by Relationships in Relationship + Categories that count as a household (`counts_as_household`). Households reflect the + relationships ongoing today. + + Send `filter_data` (the same filters as Manage Contacts) or `project_id` to count only those + Contacts' households, e.g. `filter_data[created_at_from]=01/01/2026 - 31/03/2026` for Contacts + added in a date range, or `filter_data[stories_created_at_from]=…` for Contacts with activity in + it. A household counts when at least one of its members matches, and only Contacts you may see + are matched. Each make-up counts every member, so the numbers are right; `hidden_contacts` + says how many of them you don't have permission to see. + operationId: countHouseholds + security: [{tokenAuth: []}] + parameters: + - name: filter_data + in: query + style: deepObject + explode: true + schema: + type: object + additionalProperties: true + description: Manage Contacts filters choosing the Contacts, e.g. `filter_data[project_ids][]=572` + - name: project_id + in: query + schema: + type: integer + description: Count only this Project's Contacts + responses: + "200": + description: Households and their make-up, most common make-up first + content: + application/json: + schema: + type: object + properties: + total_households: { type: integer } + contacts_in_households: + type: integer + description: How many of the matching Contacts are in a household + hidden_contacts: + type: integer + description: | + How many members of the counted households you don't have permission to see. They + are included in each make-up, so the numbers are right, but never named. + data: + type: array + items: + type: object + properties: + make_up: + type: string + example: 1 Child + 2 Parents + roles: + type: object + additionalProperties: { type: integer } + example: { Child: 1, Parent: 2 } + households: { type: integer } + hidden_contacts: + type: integer + description: Members of these households you don't have permission to see + example: + total_households: 9 + contacts_in_households: 27 + hidden_contacts: 1 + data: + - make_up: 1 Child + 1 Parent + roles: { Child: 1, Parent: 1 } + households: 6 + hidden_contacts: 0 + - make_up: 2 Children + 2 Parents + roles: { Child: 2, Parent: 2 } + households: 3 + hidden_contacts: 1 + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + /albums/{album_id}/age_bands: parameters: - name: album_id @@ -29455,6 +29541,23 @@ components: type: array description: What the Contact needs a specialist in, each Essential or Desirable, added by hand or from a form answer items: { $ref: '#/components/schemas/RequiredSkill' } + household: + description: | + The household (family) the Contact is in, from Relationships in Relationship Categories that + count as a household, or null when they are in none + nullable: true + type: object + properties: + id: { type: integer } + reference: + type: string + description: As shown on Manage Contacts, e.g. H123 + example: H123 + role: + type: string + description: The titles the Contact holds in their family relationships, e.g. Parent, or Child / Parent + example: Parent + members_count: { type: integer, example: 4 } BeneficiaryDetail: description: A Contact (Beneficiary) as returned by `GET /beneficiaries/{id}` and `POST /beneficiaries`. The list endpoint leaves out `weekly_availability`. diff --git a/server.js b/server.js index 51e0a54..0744594 100644 --- a/server.js +++ b/server.js @@ -6181,6 +6181,15 @@ function buildDocsPage() { { code: "200", cls: "response-2xx", desc: "source, total_count and data: [{band, contacts}], with \"Under X\", \"Date of birth in the future\" and \"No date of birth\" only when someone is in them" }, { code: "404", cls: "response-4xx", desc: "Not in this Organisation, or the Album or Project isn't one of its own" } ])} + ${endpointCard("GET", "/organisations/{organisation_id}/household_counts", "Count the households an Organisation's Contacts are in", true, [ + { name: "organisation_id", in: "path", type: "integer", required: true, desc: "The Organisation (Charity) ID" }, + { name: "filter_data", type: "object", required: false, desc: "Manage Contacts filters choosing the Contacts, e.g. filter_data[created_at_from]=01/01/2026 - 31/03/2026" }, + { name: "project_id", type: "integer", required: false, desc: "Count only this Project's Contacts" } + ], [ + { code: "200", cls: "response-2xx", desc: "total_households, contacts_in_households, hidden_contacts and data: [{make_up, roles, households, hidden_contacts}], most common make-up first" }, + { code: "401", cls: "response-4xx", desc: "Not authenticated" }, + { code: "404", cls: "response-4xx", desc: "Not in this Organisation" } + ], "The households panel on Manage Contacts. Contacts linked by Relationships in categories that count as a household, directly or through other Contacts, are one household. A household counts when one of its members matches the filters. Each make-up counts every member; hidden_contacts says how many you don't have permission to see.")} ${endpointCard("GET", "/albums/{album_id}/age_bands", "Get an Album's age bands", true, [ { name: "album_id", in: "path", type: "integer", required: true, desc: "The Album's (Bundle's) ID" } ], [