Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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'
Expand Down
25 changes: 25 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>beneficiary_ids</code>, or no <code>charity_id</code> when you belong to several organisations" }
], "<strong>Add to › A Checklist</strong> 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 (<code>skip_counts.not_in_project</code>), as are those you only have Headline Only Access to (<code>skip_counts.headline_only</code>). 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 (<code>GET /relationship_categories</code>)" },
{ 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: "<code>parent</code> or <code>child</code>: 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 <code>filter_data</code>" },
{ 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: <code>id</code>, <code>status</code>, <code>changed_count</code>, <code>skip_counts</code> and <code>summary</code>" },
{ code: "202", cls: "response-2xx", desc: "More than 50 Contacts: linked in the background. Poll <code>GET /beneficiaries/bulk_actions/{id}</code> with the <code>id</code>" },
{ 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 <code>beneficiary_ids</code>, or no <code>charity_id</code> when you belong to several organisations" }
], "<strong>Add to › A relationship</strong> 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 <code>skip_counts</code>: <code>already_linked</code> (they already have that relationship with that Contact), <code>same_contact</code>, <code>headline_only</code> and <code>not_allowed</code>.")}
${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: "<code>data</code>: each category's <code>id</code>, <code>parent_title</code> and <code>child_title</code> (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 <code>id</code> returned by a bulk change, e.g. <code>POST /events/{id}/guests</code> with <code>filter_data</code>" }
], [
Expand Down
Loading