diff --git a/openapi.yaml b/openapi.yaml
index ba36b91..f5183fc 100644
--- a/openapi.yaml
+++ b/openapi.yaml
@@ -1967,6 +1967,98 @@ paths:
example:
errors: ["Already exists"]
existing_id: 34
+ /audiences:
+ get:
+ tags: [Beneficiaries]
+ summary: List the organisation's audiences
+ description: |
+ The organisation's audiences (Contact Roles; Beneficiary Roles), e.g. Participant or Parent,
+ as on its Audiences page, by name. Each lists the Contact Types (Person, Organisation, …) it
+ is for. A flexible Signup Page signs people up as audiences, and a permitted relationship
+ says which audiences may be on each side of a Relationship Category. Any member of the
+ organisation can list them. `charity_id` may be left out when the user belongs to one
+ organisation.
+ operationId: listAudiences
+ 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 audiences, by name
+ content:
+ application/json:
+ schema:
+ allOf:
+ - $ref: '#/components/schemas/PaginationEnvelope'
+ - type: object
+ properties:
+ data:
+ type: array
+ items: { $ref: '#/components/schemas/Audience' }
+ "401":
+ $ref: '#/components/responses/Unauthorized'
+ "404":
+ $ref: '#/components/responses/NotFound'
+ "422":
+ $ref: '#/components/responses/UnprocessableEntityList'
+ post:
+ tags: [Beneficiaries]
+ summary: Create an audience
+ description: |
+ Adds an audience (Contact Role; Beneficiary Role), as the New Audience page does. `color` is
+ one of the approved colours (the first, `#f96d67`, if left out). `contact_type_id` links it to
+ a Contact Type (`GET /beneficiary_types`); it is linked to Person if left out. Only
+ organisation editors (Organisation Admins) may create audiences (`403` otherwise). Names
+ aren't unique, so list them first with `GET /audiences` and reuse one that fits.
+ operationId: createAudience
+ security: [{tokenAuth: []}]
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ required: [name]
+ properties:
+ charity_id:
+ type: integer
+ description: The organisation to add it to
+ name:
+ type: string
+ description: e.g. Participant
+ color:
+ type: string
+ description: |
+ One of #f96d67, #f31208, #bc1204, #f92915, #f26f21, #ff6800, #e59200, #ffa300,
+ #62a837, #71c240, #2b800e, #36ac9a, #2e9283, #226c61, #225f85, #2e85bc, #3596d6,
+ #063262, #ac3898, #6c235f, #620a4d, #8c1b6d, #d07db7, #a81e6a, #e82a92, #8e0132
+ contact_type_id:
+ type: integer
+ description: The Contact Type (Beneficiary Type) it is for; Person if left out
+ example:
+ charity_id: 12
+ name: Parent
+ color: '#ac3898'
+ responses:
+ "201":
+ description: The audience made
+ content:
+ application/json:
+ schema: { $ref: '#/components/schemas/Audience' }
+ "401":
+ $ref: '#/components/responses/Unauthorized'
+ "403":
+ $ref: '#/components/responses/ForbiddenError'
+ "404":
+ $ref: '#/components/responses/NotFound'
+ "422":
+ $ref: '#/components/responses/UnprocessableEntityList'
/beneficiaries/bulk_actions/{id}:
get:
tags: [Beneficiaries]
@@ -14028,6 +14120,26 @@ components:
created_at: { type: string, format: date-time }
updated_at: { type: string, format: date-time }
+ Audience:
+ type: object
+ description: An audience (Contact Role; Beneficiary Role), e.g. Participant or Parent
+ properties:
+ id: { type: integer }
+ name: { type: string }
+ color:
+ type: string
+ description: Its colour on the Audiences page, e.g. '#f96d67'
+ contact_types:
+ type: array
+ description: The Contact Types (Beneficiary Types) it is for
+ items:
+ type: object
+ properties:
+ id: { type: integer }
+ name: { type: string }
+ 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 696e2ce..dad3d36 100644
--- a/server.js
+++ b/server.js
@@ -1615,6 +1615,28 @@ function buildDocsPage() {
{ code: "404", cls: "response-4xx", desc: "An organisation you aren't in" },
{ code: "422", cls: "response-4xx", desc: "A title is missing, or the pair already exists in any case: existing_id is the one already there, to reuse" }
], "New Relationship Type on the organisation's Relationship Types page, e.g. Parent & Child or Client & Emergency Contact. A fixed Signup Page needs one to connect the people it signs up. List them first and reuse one that fits.")}
+ ${endpointCard("GET", "/audiences", "List the organisation's audiences", 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 audiences changed since then" }
+ ], [
+ { code: "200", cls: "response-2xx", desc: "data: each audience's id, name, color and contact_types, by name, in the paginated envelope" },
+ { code: "401", cls: "response-4xx", desc: "Not authenticated" },
+ { code: "404", cls: "response-4xx", desc: "An organisation you aren't in" }
+ ], "Audiences (Contact Roles), e.g. Participant or Parent, as on the organisation's Audiences page. A flexible Signup Page signs people up as audiences. Any member of the organisation can list them.")}
+ ${endpointCard("POST", "/audiences", "Create an audience", true, [
+ { name: "charity_id", in: "body", type: "integer", required: false, desc: "The organisation. Optional if you belong to only one" },
+ { name: "name", in: "body", type: "string", required: true, desc: "e.g. Participant" },
+ { name: "color", in: "body", type: "string", required: false, desc: "One of the approved colours; #f96d67 if left out" },
+ { name: "contact_type_id", in: "body", type: "integer", required: false, desc: "The Contact Type (GET /beneficiary_types); Person if left out" }
+ ], [
+ { code: "201", cls: "response-2xx", desc: "The audience made" },
+ { code: "401", cls: "response-4xx", desc: "Not authenticated" },
+ { code: "403", cls: "response-4xx", desc: "You aren't an organisation editor (Organisation Admin)" },
+ { code: "404", cls: "response-4xx", desc: "An organisation you aren't in" },
+ { code: "422", cls: "response-4xx", desc: "No name, a colour that isn't approved, or an unknown Contact Type" }
+ ], "New Audience on the Audiences page. Names aren't unique: list them first and reuse one that fits.")}
${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" }
], [