From 4559e1959358357ec163df94743b30738f99ff2f Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Nov 2026 10:28:59 +0000 Subject: [PATCH] Document linking Labels to Outcomes, and label_results CP-9367. Adds GET and PUT /labels/{label_id}/outcomes and /outcomes/{outcome_id}/labels to openapi.yaml and the Labels section, and label_results on GET /project_results. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01F1a5xon4NMHuPrEHjy3v2f --- openapi.yaml | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++- server.js | 35 ++++++++++- 2 files changed, 197 insertions(+), 3 deletions(-) diff --git a/openapi.yaml b/openapi.yaml index cef4ac8..c638012 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -4354,11 +4354,28 @@ paths: `default_results_template_id` on `GET /projects/{id}`. Omit for every tracker. responses: "200": - description: One page of trackers + description: One page of trackers, plus label_results content: application/json: schema: - $ref: '#/components/schemas/PaginatedProjectResults' + allOf: + - $ref: '#/components/schemas/PaginatedProjectResults' + - type: object + properties: + label_results: + type: array + description: | + Each Label (Story Label) that evidences one of the Projects' Outcomes, with the Stories and survey + responses carrying it dated in the timeframe, and its deadline targets dated in it. Not paginated. + items: + type: object + properties: + label_id: { type: integer } + label_name: { type: string } + outcome_id: { type: integer } + outcome_name: { type: string } + story_count: { type: integer } + target: { type: integer, nullable: true } "401": $ref: '#/components/responses/Unauthorized' "422": @@ -7009,6 +7026,124 @@ paths: $ref: '#/components/responses/NotFound' "422": $ref: '#/components/responses/UnprocessableEntity' + /labels/{label_id}/outcomes: + parameters: + - name: label_id + in: path + required: true + schema: { type: integer } + get: + tags: [Labels] + summary: List the Outcomes a Label evidences + description: | + Stories and survey responses with a Label show under the Outcomes it evidences on a Project's Results Canvas. + `editable` is false for an Outcome you can't edit, whose link you can't remove. + operationId: listLabelOutcomes + security: [{tokenAuth: []}] + parameters: + - $ref: '#/components/parameters/Page' + - $ref: '#/components/parameters/PerPage' + responses: + "200": + description: The linked Outcomes + content: + application/json: + schema: { $ref: '#/components/schemas/LabelOutcomesPage' } + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + put: + tags: [Labels] + summary: Set the Outcomes a Label evidences + description: | + `outcome_ids` replaces the links you may change. Links to Outcomes you can't edit are kept. You can only link + Outcomes you can edit. Linking from the Outcome side edits the same links. + operationId: setLabelOutcomes + security: [{tokenAuth: []}] + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [outcome_ids] + properties: + outcome_ids: { type: array, items: { type: integer } } + example: + outcome_ids: [5120, 5121] + responses: + "200": + description: The linked Outcomes + content: + application/json: + schema: { $ref: '#/components/schemas/LabelOutcomesPage' } + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + "422": + $ref: '#/components/responses/UnprocessableEntityList' + /outcomes/{outcome_id}/labels: + parameters: + - name: outcome_id + in: path + required: true + schema: { type: integer } + get: + tags: [Labels] + summary: List the Labels that evidence an Outcome + description: | + Your organisations' Labels linked to the Outcome. Other organisations' Labels are counted in `other_label_count`. + `editable` says whether you may change the Outcome's Labels. + operationId: listOutcomeLabels + security: [{tokenAuth: []}] + parameters: + - $ref: '#/components/parameters/Page' + - $ref: '#/components/parameters/PerPage' + responses: + "200": + description: The linked Labels + content: + application/json: + schema: { $ref: '#/components/schemas/OutcomeLabelsPage' } + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + put: + tags: [Labels] + summary: Set the Labels that evidence an Outcome + description: | + `label_ids` replaces your organisations' Labels on the Outcome; other organisations' are kept. You must be able + to edit the Outcome. + operationId: setOutcomeLabels + security: [{tokenAuth: []}] + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [label_ids] + properties: + label_ids: { type: array, items: { type: integer } } + example: + label_ids: [412] + responses: + "200": + description: The linked Labels + content: + application/json: + schema: { $ref: '#/components/schemas/OutcomeLabelsPage' } + "401": + $ref: '#/components/responses/Unauthorized' + "403": + $ref: '#/components/responses/ForbiddenError' + "404": + $ref: '#/components/responses/NotFound' + "422": + $ref: '#/components/responses/UnprocessableEntityList' /stories/{story_id}/labels: parameters: - name: story_id @@ -27959,6 +28094,32 @@ components: name: { type: string, maxLength: 255 } color: { type: string, pattern: '^#[0-9a-fA-F]{6}$', description: 'Default #3595d5' } privacy: { type: string, enum: [only_charity_colleagues, everyone], description: Default only_charity_colleagues } + LabelOutcomesPage: + allOf: + - $ref: '#/components/schemas/PaginationEnvelope' + - type: object + properties: + label_id: { type: integer } + data: + type: array + items: + type: object + properties: + id: { type: integer } + title: { type: string } + project_count: { type: integer, description: How many projects use the Outcome } + editable: { type: boolean, description: Whether you may remove this link } + OutcomeLabelsPage: + allOf: + - $ref: '#/components/schemas/PaginationEnvelope' + - type: object + properties: + outcome_id: { type: integer } + editable: { type: boolean } + other_label_count: { type: integer } + data: + type: array + items: { $ref: '#/components/schemas/Label' } StoryLabelsResult: type: object properties: diff --git a/server.js b/server.js index f345896..917bde1 100644 --- a/server.js +++ b/server.js @@ -1441,7 +1441,7 @@ function buildDocsPage() { { name: "page", type: "integer", required: false, desc: "Page number (default 1)" }, { name: "per_page", type: "integer", required: false, desc: "Trackers per page (default 10, max 200)" } ], [ - { code: "200", cls: "response-2xx", desc: "Paginated trackers, plus start_date, end_date and project_ids" }, + { code: "200", cls: "response-2xx", desc: "Paginated trackers, plus start_date, end_date, project_ids and label_results: each Label that evidences the Projects' Outcomes, with its story_count in the timeframe and target" }, { code: "401", cls: "response-4xx", desc: "Not authenticated" }, { code: "422", cls: "response-4xx", desc: "Invalid project_ids, date, tracker_types, group_by, per_page or template_id" } ], "Returns the figures on each Project's Results Canvas (the Results panel on a Project page), one entry per tracker, for the Projects you can view. Activity and Engagement trackers (Changes) give times_recorded and contacts; Achievement trackers (Binary Indicators) give times_recorded and contacts_achieved; Choice trackers (Scale Indicators) give answers with a count and contacts per Sub Ratio; Numerical trackers (Value Indicators) give total and average_per_contact. times_recorded counts records, not people; contacts counts distinct Contacts tagged. anonymous_count is what was recorded with no Contact tagged. target, target_deadline and percent_of_target appear when the Project has a target.")} @@ -2526,6 +2526,39 @@ function buildDocsPage() { { code: "401", cls: "response-4xx", desc: "Not authenticated" }, { code: "404", cls: "response-4xx", desc: "Not one of your organisations' Labels" } ], "The Stories and survey responses with this Label that you can see: ids and dates only. Fetch one with GET /stories/{id}.")} + ${endpointCard("GET", "/labels/{label_id}/outcomes", "List the Outcomes a Label evidences", true, [ + { name: "label_id", in: "path", type: "integer", required: true, desc: "The Label" } + ], [ + { code: "200", cls: "response-2xx", desc: "data: each Outcome's id, title, project_count and editable" }, + { code: "401", cls: "response-4xx", desc: "Not authenticated" }, + { code: "404", cls: "response-4xx", desc: "Not one of your organisations' Labels" } + ], "Stories with the Label show under these Outcomes on the Results Canvas. editable is false for an Outcome you can't edit.")} + ${endpointCard("PUT", "/labels/{label_id}/outcomes", "Set the Outcomes a Label evidences", true, [ + { name: "label_id", in: "path", type: "integer", required: true, desc: "The Label" }, + { name: "outcome_ids", in: "body", type: "integer[]", required: true, desc: "Every Outcome the Label should evidence" } + ], [ + { code: "200", cls: "response-2xx", desc: "The linked Outcomes" }, + { code: "401", cls: "response-4xx", desc: "Not authenticated" }, + { code: "404", cls: "response-4xx", desc: "Not one of your organisations' Labels" }, + { code: "422", cls: "response-4xx", desc: "An Outcome you can't edit" } + ], "Replaces the links you may change; links to Outcomes you can't edit are kept.")} + ${endpointCard("GET", "/outcomes/{outcome_id}/labels", "List the Labels that evidence an Outcome", true, [ + { name: "outcome_id", in: "path", type: "integer", required: true, desc: "The Outcome" } + ], [ + { code: "200", cls: "response-2xx", desc: "data: your organisations' Labels, plus editable and other_label_count" }, + { code: "401", cls: "response-4xx", desc: "Not authenticated" }, + { code: "404", cls: "response-4xx", desc: "An Outcome you can't see" } + ])} + ${endpointCard("PUT", "/outcomes/{outcome_id}/labels", "Set the Labels that evidence an Outcome", true, [ + { name: "outcome_id", in: "path", type: "integer", required: true, desc: "The Outcome" }, + { name: "label_ids", in: "body", type: "integer[]", required: true, desc: "Every one of your Labels that should evidence it" } + ], [ + { code: "200", cls: "response-2xx", desc: "The linked Labels" }, + { code: "401", cls: "response-4xx", desc: "Not authenticated" }, + { code: "403", cls: "response-4xx", desc: "An Outcome you can't edit" }, + { code: "404", cls: "response-4xx", desc: "An Outcome you can't see" }, + { code: "422", cls: "response-4xx", desc: "A Label that isn't your organisations'" } + ], "Other organisations' Labels on the Outcome are kept.")} ${endpointCard("POST", "/stories/{story_id}/labels", "Add a Label to a Story", true, [ { name: "story_id", in: "path", type: "integer", required: true, desc: "The Story or survey response" }, { name: "label_id", in: "body", type: "integer", required: true, desc: "The Label" }