diff --git a/openapi.yaml b/openapi.yaml
index e29ed4b..0105b45 100644
--- a/openapi.yaml
+++ b/openapi.yaml
@@ -7563,6 +7563,146 @@ paths:
"401":
$ref: '#/components/responses/Unauthorized'
+ /stories/search:
+ get:
+ tags: [Stories]
+ summary: Search Stories by keyword, Label or Outcome
+ description: |
+ Searches the text of the Stories and survey responses you can see, and their written answers to Survey
+ questions, and returns a short snippet of each match. Search by `query` (keywords or a phrase; word forms
+ match, so "confident" finds "confidence"), by `label_ids` (Stories carrying any of these Labels), or by
+ `outcome_id` (Stories carrying a Label linked to that Outcome). Give at least one of the three. With a
+ query, results are ordered by relevance; without one, newest first. Contacts' names in snippets are
+ replaced with "[name]". `total_count` stops at 1000, and `total_count_capped` is then true. Label ids that
+ aren't your organisations' are ignored and listed in `ignored_label_ids`.
+ operationId: searchStories
+ security: [{tokenAuth: []}]
+ parameters:
+ - $ref: '#/components/parameters/Page'
+ - name: per_page
+ in: query
+ description: Default 10, at most 25
+ schema: { type: integer, default: 10, maximum: 25 }
+ - name: query
+ in: query
+ description: Keywords or a phrase
+ schema: { type: string }
+ example: found a job
+ - name: label_ids[]
+ in: query
+ description: Only Stories carrying any of these Labels
+ schema: { type: array, items: { type: integer } }
+ - name: outcome_id
+ in: query
+ description: Only Stories carrying a Label linked to this Outcome
+ schema: { type: integer }
+ - name: project_ids[]
+ in: query
+ description: Only these projects; by default every project you can see
+ schema: { type: array, items: { type: integer } }
+ - name: story_category_id
+ in: query
+ description: Only Stories of this Survey (Story Category)
+ schema: { type: integer }
+ - name: start_date
+ in: query
+ description: Earliest Story date, YYYY-MM-DD
+ schema: { type: string, format: date }
+ - name: end_date
+ in: query
+ description: Latest Story date, YYYY-MM-DD
+ schema: { type: string, format: date }
+ responses:
+ "200":
+ description: A page of matching Stories with snippets
+ content:
+ application/json:
+ schema:
+ allOf:
+ - $ref: '#/components/schemas/PaginationEnvelope'
+ - type: object
+ properties:
+ total_count_capped: { type: boolean, description: True when more than 1000 Stories match }
+ ignored_label_ids: { type: array, items: { type: integer } }
+ data:
+ type: array
+ items:
+ type: object
+ properties:
+ story_id: { type: integer }
+ story_category: { type: string, description: The Survey's name }
+ project: { type: string }
+ created_at: { type: string, format: date }
+ labels: { type: array, items: { type: string } }
+ snippet: { type: string, description: "Up to 300 characters, with Contacts' names replaced by [name]" }
+ example:
+ page: 1
+ page_size: 1
+ page_count: 1
+ total_count: 1
+ total_count_capped: false
+ ignored_label_ids: []
+ data:
+ - story_id: 1234
+ story_category: Exit survey
+ project: Into work
+ created_at: "2026-03-10"
+ labels: [Found work]
+ snippet: "[name] found a job at the bakery after six weeks of mentoring."
+ "401":
+ $ref: '#/components/responses/Unauthorized'
+ "422":
+ $ref: '#/components/responses/UnprocessableEntity'
+ /stories/search_labels:
+ get:
+ tags: [Stories]
+ summary: List the Labels used on Stories, with counts
+ description: |
+ The Labels carried by the Stories you can see in the given projects and dates, with how many Stories carry
+ each and the Outcomes each is linked to. Labels no Story there carries are left out. Use the ids with
+ GET /stories/search.
+ operationId: listStorySearchLabels
+ security: [{tokenAuth: []}]
+ parameters:
+ - name: project_ids[]
+ in: query
+ description: Only these projects; by default every project you can see
+ schema: { type: array, items: { type: integer } }
+ - name: start_date
+ in: query
+ description: Earliest Story date, YYYY-MM-DD
+ schema: { type: string, format: date }
+ - name: end_date
+ in: query
+ description: Latest Story date, YYYY-MM-DD
+ schema: { type: string, format: date }
+ responses:
+ "200":
+ description: The Labels in use, by name
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ data:
+ type: array
+ items:
+ type: object
+ properties:
+ id: { type: integer }
+ name: { type: string }
+ stories_in_scope: { type: integer }
+ outcomes:
+ type: array
+ items:
+ type: object
+ properties:
+ id: { type: integer }
+ title: { type: string }
+ "401":
+ $ref: '#/components/responses/Unauthorized'
+ "422":
+ $ref: '#/components/responses/UnprocessableEntity'
/story_categories:
get:
tags: [Story Categories]
diff --git a/server.js b/server.js
index fdc2f22..ca7c636 100644
--- a/server.js
+++ b/server.js
@@ -2469,6 +2469,29 @@ function buildDocsPage() {
{ name: "start_date", type: "string", required: false, desc: "YYYY-MM-DD — stories on or after this date" },
{ name: "end_date", type: "string", required: false, desc: "YYYY-MM-DD — stories on or before this date" }
], [{ code: "200", cls: "response-2xx", desc: "Stories enriched with named Indicators, Changes, and Custom Field values — ideal for reporting" }])}
+ ${endpointCard("GET", "/stories/search", "Search Stories by keyword, Label or Outcome", true, [
+ { name: "query", in: "query", type: "string", required: false, desc: "Keywords or a phrase; word forms match" },
+ { name: "label_ids[]", in: "query", type: "integer[]", required: false, desc: "Only Stories carrying any of these Labels" },
+ { name: "outcome_id", in: "query", type: "integer", required: false, desc: "Only Stories carrying a Label linked to this Outcome" },
+ { name: "project_ids[]", in: "query", type: "integer[]", required: false, desc: "Only these projects; by default every project you can see" },
+ { name: "story_category_id", in: "query", type: "integer", required: false, desc: "Only Stories of this Survey" },
+ { name: "start_date", in: "query", type: "string", required: false, desc: "YYYY-MM-DD" },
+ { name: "end_date", in: "query", type: "string", required: false, desc: "YYYY-MM-DD" },
+ { name: "page", in: "query", type: "integer", required: false, desc: "Page number" },
+ { name: "per_page", in: "query", type: "integer", required: false, desc: "Default 10, max 25" }
+ ], [
+ { code: "200", cls: "response-2xx", desc: "data: each match's story_id, story_category, project, created_at, labels and snippet, in the paginated envelope, plus total_count_capped and ignored_label_ids" },
+ { code: "401", cls: "response-4xx", desc: "Not authenticated" },
+ { code: "422", cls: "response-4xx", desc: "None of query, label_ids or outcome_id, a date not in YYYY-MM-DD, or per_page over 25" }
+ ], "Give at least one of query, label_ids or outcome_id. Searches Story text and written Survey answers; snippets are up to 300 characters with Contacts' names replaced by [name]. With a query, results are ordered by relevance; without one, newest first. total_count stops at 1000.")}
+ ${endpointCard("GET", "/stories/search_labels", "List the Labels used on Stories, with counts", true, [
+ { name: "project_ids[]", in: "query", type: "integer[]", required: false, desc: "Only these projects; by default every project you can see" },
+ { name: "start_date", in: "query", type: "string", required: false, desc: "YYYY-MM-DD" },
+ { name: "end_date", in: "query", type: "string", required: false, desc: "YYYY-MM-DD" }
+ ], [
+ { code: "200", cls: "response-2xx", desc: "data: each Label's id, name, stories_in_scope and linked outcomes" },
+ { code: "401", cls: "response-4xx", desc: "Not authenticated" }
+ ], "Only Labels that Stories in those projects and dates carry. Use the ids with GET /stories/search.")}
${endpointCard("GET", "/stories/{id}/attachments", "Get attachments for a Story", true, [
{ name: "id", in: "path", type: "integer", required: true, desc: "Story ID" }
], [{ code: "200", cls: "response-2xx", desc: "Paginated media attachments" }])}