diff --git a/openapi.yaml b/openapi.yaml
index ccebc4b..a5e77f3 100644
--- a/openapi.yaml
+++ b/openapi.yaml
@@ -1769,6 +1769,140 @@ paths:
$ref: '#/components/responses/NotFound'
"422":
$ref: '#/components/responses/UnprocessableEntityList'
+ /beneficiaries/bulk_relationships:
+ post:
+ tags: [Beneficiaries]
+ summary: Link many Contacts to one Contact with the same relationship
+ description: |
+ Gives many Contacts (Beneficiaries) the same relationship with one Contact, in one request.
+ This is **Add to › A relationship** for the Contacts selected on the Manage Contacts page,
+ e.g. making Oakfield School the School of every selected pupil. Each relationship is added
+ the same way as Add a Relationship on a Contact's profile, so it appears on both Contacts'
+ History.
+
+ **Which relationship.** `relationship_category_id` is one of the organisation's
+ Relationship Categories (`GET /relationship_categories`), which has two sides, e.g. School &
+ Pupil. `related_contact_id` is the one Contact everyone is linked to, and
+ `related_contact_is` says which side that Contact takes: `parent` (the first title, School)
+ or `child` (the second, Pupil). Each selected Contact takes the other side.
+
+ **Which Contacts.** Either `beneficiary_ids` (at most 500), or everyone matching
+ `filter_data` (the Manage Contacts filters) leaving out `excluded_ids`.
+
+ **Skipped Contacts** are counted in `skip_counts`: `headline_only` (the user only has
+ Headline Only Access to them), `already_linked` (they already have that relationship with
+ that Contact), `same_contact` (the chosen Contact itself), `not_allowed` (the relationship
+ couldn't be saved for them).
+
+ Up to 50 Contacts are linked straight away (`200`); more run in the background (`202`), and
+ `GET /beneficiaries/bulk_actions/{id}` reports the progress. `charity_id` may be left out when
+ the user belongs to one organisation.
+ operationId: linkBeneficiariesToContact
+ security: [{tokenAuth: []}]
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ required: [relationship_category_id, related_contact_id, related_contact_is]
+ properties:
+ charity_id:
+ type: integer
+ description: The organisation whose Contacts to link
+ relationship_category_id:
+ type: integer
+ description: One of the organisation's Relationship Categories
+ related_contact_id:
+ type: integer
+ description: The Contact every selected Contact is linked to
+ related_contact_is:
+ type: string
+ enum: [parent, child]
+ description: Which side of the category the related Contact takes; the selected Contacts take the other
+ beneficiary_ids:
+ type: array
+ maxItems: 500
+ items: { type: integer }
+ description: The Contacts to link, at most 500. Leave out to use filter_data instead.
+ filter_data:
+ type: object
+ additionalProperties: true
+ description: Manage Contacts filters selecting the Contacts, used when beneficiary_ids is left out
+ excluded_ids:
+ type: array
+ items: { type: integer }
+ description: Contacts matching the filters to leave out
+ example:
+ charity_id: 12
+ relationship_category_id: 8
+ related_contact_id: 160400
+ related_contact_is: parent
+ beneficiary_ids: [160498, 160499, 160500]
+ responses:
+ "200":
+ description: The Contacts were linked straight away (50 or fewer)
+ content:
+ application/json:
+ schema: { $ref: '#/components/schemas/BeneficiaryBulkAction' }
+ example:
+ id: 71
+ status: completed
+ total_count: 5
+ processed_count: 5
+ changed_count: 5
+ skip_counts: {}
+ background: false
+ summary: "5 contacts changed."
+ "202":
+ description: More than 50 Contacts, so they are linked in the background. Poll GET /beneficiaries/bulk_actions/{id}.
+ content:
+ application/json:
+ schema: { $ref: '#/components/schemas/BeneficiaryBulkAction' }
+ "401":
+ $ref: '#/components/responses/Unauthorized'
+ "404":
+ $ref: '#/components/responses/NotFound'
+ "422":
+ $ref: '#/components/responses/UnprocessableEntityList'
+ /relationship_categories:
+ get:
+ tags: [Beneficiaries]
+ summary: List the organisation's Relationship Categories
+ description: |
+ The kinds of relationship Contacts can have with each other in the organisation, each with
+ its two sides, e.g. School & Pupil or Mother & Son. Use an `id` with
+ `POST /beneficiaries/bulk_relationships`. Any member of the organisation can list them.
+ `charity_id` may be left out when the user belongs to one organisation.
+ operationId: listRelationshipCategories
+ security: [{tokenAuth: []}]
+ parameters:
+ - name: charity_id
+ in: query
+ required: false
+ schema: { type: integer }
+ - $ref: '#/components/parameters/Page'
+ - $ref: '#/components/parameters/PerPage'
+ - $ref: '#/components/parameters/LastSyncDatetime'
+ responses:
+ "200":
+ description: A page of Relationship Categories, by title
+ content:
+ application/json:
+ schema:
+ allOf:
+ - $ref: '#/components/schemas/PaginationEnvelope'
+ - type: object
+ properties:
+ data:
+ type: array
+ items: { $ref: '#/components/schemas/RelationshipCategory' }
+ "401":
+ $ref: '#/components/responses/Unauthorized'
+ "404":
+ $ref: '#/components/responses/NotFound'
+ "422":
+ $ref: '#/components/responses/UnprocessableEntityList'
/beneficiaries/bulk_actions/{id}:
get:
tags: [Beneficiaries]
@@ -13816,6 +13950,20 @@ components:
nullable: true
description: The finished message, e.g. "6 contacts changed. 1 skipped …"; null until it has finished
+ RelationshipCategory:
+ type: object
+ description: A kind of relationship between Contacts, with its two sides
+ properties:
+ id: { type: integer }
+ parent_title:
+ type: string
+ description: The first side, e.g. School
+ child_title:
+ type: string
+ description: The second side, e.g. Pupil
+ created_at: { type: string, format: date-time }
+ updated_at: { type: string, format: date-time }
+
EventGuestsBulkAdd:
allOf:
- $ref: '#/components/schemas/BeneficiaryBulkAction'
diff --git a/server.js b/server.js
index c65f073..5bec9d5 100644
--- a/server.js
+++ b/server.js
@@ -1579,6 +1579,31 @@ function buildDocsPage() {
{ code: "404", cls: "response-4xx", desc: "An organisation you aren't in" },
{ code: "422", cls: "response-4xx", desc: "A Checklist or Project you can't start it through, more than 500 beneficiary_ids, or no charity_id when you belong to several organisations" }
], "Add to › A Checklist for the Contacts selected on the Manage Contacts page. Each Contact is started as Add a Checklist on their profile does, and steps their records already prove done are ticked off. Contacts outside the Project are skipped (skip_counts.not_in_project), as are those you only have Headline Only Access to (skip_counts.headline_only). Contacts who already have the Checklist keep their progress. Organisation Editors and Reporters may use any open Project; others only Projects they are an Editor or Reporter of.")}
+ ${endpointCard("POST", "/beneficiaries/bulk_relationships", "Link many Contacts to one Contact with the same relationship", true, [
+ { name: "relationship_category_id", in: "body", type: "integer", required: true, desc: "One of the organisation's Relationship Categories (GET /relationship_categories)" },
+ { name: "related_contact_id", in: "body", type: "integer", required: true, desc: "The Contact everyone is linked to" },
+ { name: "related_contact_is", in: "body", type: "string", required: true, desc: "parent or child: which side of the category the related Contact takes. The selected Contacts take the other" },
+ { name: "charity_id", in: "body", type: "integer", required: false, desc: "The organisation. Optional if you belong to only one" },
+ { name: "beneficiary_ids", in: "body", type: "integer[]", required: false, desc: "The Contacts, at most 500. Leave out to choose them with filter_data" },
+ { name: "filter_data", in: "body", type: "object", required: false, desc: "Manage Contacts filters choosing the Contacts" },
+ { name: "excluded_ids", in: "body", type: "integer[]", required: false, desc: "Contacts matching the filters to leave out" }
+ ], [
+ { code: "200", cls: "response-2xx", desc: "Up to 50 Contacts, linked straight away: id, status, changed_count, skip_counts and summary" },
+ { code: "202", cls: "response-2xx", desc: "More than 50 Contacts: linked in the background. Poll GET /beneficiaries/bulk_actions/{id} with the id" },
+ { code: "401", cls: "response-4xx", desc: "Not authenticated" },
+ { code: "404", cls: "response-4xx", desc: "An organisation you aren't in" },
+ { code: "422", cls: "response-4xx", desc: "Another organisation's category or Contact, an unknown side, more than 500 beneficiary_ids, or no charity_id when you belong to several organisations" }
+ ], "Add to › A relationship for the Contacts selected on the Manage Contacts page, e.g. making Oakfield School the School of every selected pupil. Each relationship is added as Add a Relationship on a Contact's profile does and appears on both Contacts' History. Skipped Contacts are counted in skip_counts: already_linked (they already have that relationship with that Contact), same_contact, headline_only and not_allowed.")}
+ ${endpointCard("GET", "/relationship_categories", "List the organisation's Relationship Categories", true, [
+ { name: "charity_id", in: "query", type: "integer", required: false, desc: "The organisation. Optional if you belong to only one" },
+ { name: "page", in: "query", type: "integer", required: false, desc: "Page number" },
+ { name: "per_page", in: "query", type: "integer", required: false, desc: "Default 10, max 200" },
+ { name: "last_synced_datetime", in: "query", type: "string", required: false, desc: "Only categories changed since then" }
+ ], [
+ { code: "200", cls: "response-2xx", desc: "data: each category's id, parent_title and child_title (e.g. School and Pupil), in the paginated envelope" },
+ { code: "401", cls: "response-4xx", desc: "Not authenticated" },
+ { code: "404", cls: "response-4xx", desc: "An organisation you aren't in" }
+ ], "The kinds of relationship Contacts can have with each other in the organisation. Any member of the organisation can list them.")}
${endpointCard("GET", "/beneficiaries/bulk_actions/{id}", "Get the progress of a bulk action on Contacts", true, [
{ name: "id", in: "path", type: "integer", required: true, desc: "The id returned by a bulk change, e.g. POST /events/{id}/guests with filter_data" }
], [