Skip to content
Merged
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
247 changes: 247 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ tags:
description: Cases linked to a Beneficiary and a Project
- name: Stories
description: Survey responses, timeline updates, and instant updates — the primary content format
- name: Labels
description: Story Labels — an organisation's themes for coding Stories and survey responses
- name: Story Categories
description: Surveys — form templates used to create Stories
- name: Project Story Categories
Expand Down Expand Up @@ -6862,6 +6864,215 @@ paths:
"422":
$ref: '#/components/responses/UnprocessableEntity'

/labels:
get:
tags: [Labels]
summary: List your organisations' Labels
description: |
The Labels (Story Labels) of the organisations you belong to, by name: the ones the Label popup
on a Story offers. Organisations use them to code Stories and survey responses by theme.
operationId: listLabels
security: [{tokenAuth: []}]
parameters:
- name: charity_id
in: query
required: false
schema: { type: integer }
description: Only this organisation's Labels
- name: search
in: query
required: false
schema: { type: string }
description: Part of the name, case-insensitive
- $ref: '#/components/parameters/Page'
- $ref: '#/components/parameters/PerPage'
- $ref: '#/components/parameters/LastSyncDatetime'
responses:
"200":
description: A page of Labels, by name
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/PaginationEnvelope'
- type: object
properties:
data:
type: array
items: { $ref: '#/components/schemas/Label' }
"401":
$ref: '#/components/responses/Unauthorized'
"422":
$ref: '#/components/responses/UnprocessableEntity'
post:
tags: [Labels]
summary: Create a Label
description: Creates a Label for one of your organisations.
operationId: createLabel
security: [{tokenAuth: []}]
requestBody:
required: true
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/LabelInput'
- required: [charity_id, name]
example:
charity_id: 913
name: Housing
color: '#36ac9a'
privacy: only_charity_colleagues
responses:
"201":
description: The new Label
content:
application/json:
schema: { $ref: '#/components/schemas/Label' }
"401":
$ref: '#/components/responses/Unauthorized'
"403":
$ref: '#/components/responses/ForbiddenError'
"422":
$ref: '#/components/responses/UnprocessableEntityList'
/labels/{id}:
patch:
tags: [Labels]
summary: Change a Label
description: Renames a Label, changes its colour or privacy, or moves it to another of your organisations. Only the fields sent change.
operationId: updateLabel
security: [{tokenAuth: []}]
parameters:
- name: id
in: path
required: true
schema: { type: integer }
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/LabelInput' }
example:
name: Safe housing
responses:
"200":
description: The Label
content:
application/json:
schema: { $ref: '#/components/schemas/Label' }
"401":
$ref: '#/components/responses/Unauthorized'
"403":
$ref: '#/components/responses/ForbiddenError'
"404":
$ref: '#/components/responses/NotFound'
"422":
$ref: '#/components/responses/UnprocessableEntityList'
/labels/{id}/stories:
get:
tags: [Labels]
summary: List a Label's Stories
description: |
The Stories and survey responses with this Label that you can see, newest first: ids and dates
only. Fetch one with GET /stories/{id}.
operationId: listLabelStories
security: [{tokenAuth: []}]
parameters:
- name: id
in: path
required: true
schema: { type: integer }
- $ref: '#/components/parameters/Page'
- $ref: '#/components/parameters/PerPage'
responses:
"200":
description: A page of labelled Stories
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/PaginationEnvelope'
- type: object
properties:
data:
type: array
items:
type: object
properties:
id: { type: integer }
actual_created_at: { type: string, format: date-time, description: Date Posted }
created_at: { type: string, format: date-time, description: Date Happened }
labelled_at: { type: string, format: date-time }
"401":
$ref: '#/components/responses/Unauthorized'
"404":
$ref: '#/components/responses/NotFound'
"422":
$ref: '#/components/responses/UnprocessableEntity'
/stories/{story_id}/labels:
parameters:
- name: story_id
in: path
required: true
schema: { type: integer }
post:
tags: [Labels]
summary: Add a Label to a Story
description: Adds one of your organisations' Labels to a Story or survey response you can see. Adding one it already has changes nothing.
operationId: addStoryLabel
security: [{tokenAuth: []}]
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [label_id]
properties:
label_id: { type: integer }
example:
label_id: 412
responses:
"201":
description: The Label and the Story's Labels
content:
application/json:
schema: { $ref: '#/components/schemas/StoryLabelsResult' }
"401":
$ref: '#/components/responses/Unauthorized'
"404":
$ref: '#/components/responses/NotFound'
"422":
$ref: '#/components/responses/UnprocessableEntityList'
delete:
tags: [Labels]
summary: Take a Label off a Story
description: Takes a Label off a Story or survey response. Removing one it hasn't got changes nothing.
operationId: removeStoryLabel
security: [{tokenAuth: []}]
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [label_id]
properties:
label_id: { type: integer }
example:
label_id: 412
responses:
"200":
description: The Label and the Story's remaining Labels
content:
application/json:
schema: { $ref: '#/components/schemas/StoryLabelsResult' }
"401":
$ref: '#/components/responses/Unauthorized'
"404":
$ref: '#/components/responses/NotFound'
"422":
$ref: '#/components/responses/UnprocessableEntityList'
/stories/{id}:
get:
tags: [Stories]
Expand Down Expand Up @@ -28059,6 +28270,37 @@ components:
type: string
enum: [Person, Organisation, Animal, Object]

Label:
type: object
description: A Label (Story Label), one of an organisation's themes for coding Stories and survey responses
properties:
id: { type: integer, example: 412 }
name: { type: string, example: Housing }
color: { type: string, description: Hex colour, example: '#36ac9a' }
charity_id: { type: integer, description: The organisation that owns the Label, example: 913 }
user_id: { type: integer, nullable: true, description: Who created it }
privacy:
type: string
enum: [only_charity_colleagues, everyone]
description: Who may open the Label's page
created_at: { type: string, format: date-time }
updated_at: { type: string, format: date-time }
LabelInput:
type: object
properties:
charity_id: { type: integer, description: The organisation that owns the Label. Must be one you belong to. }
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 }
StoryLabelsResult:
type: object
properties:
story_id: { type: integer }
label: { $ref: '#/components/schemas/Label' }
label_ids:
type: array
items: { type: integer }
description: Your organisations' Labels now on the Story
Flag:
type: object
description: A Flag (Contact Flag) of the organisation
Expand Down Expand Up @@ -28287,6 +28529,11 @@ components:
id:
type: integer
example: 369011
label_ids:
type: array
items: { type: integer }
description: The Labels (Story Labels) on the Story. Returned by GET /stories/{id}.
example: [412, 418]
text:
type: string
nullable: true
Expand Down
74 changes: 74 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ function buildDocsPage() {
<div class="nav-section-label">Surveys &amp; stories</div>
<a href="#surveys" class="nav-link"><span class="nav-method method-GET">GET</span>Surveys</a>
<a href="#stories" class="nav-link"><span class="nav-method method-POST">POST</span>Stories</a>
<a href="#labels" class="nav-link"><span class="nav-method method-GET">GET</span>Labels</a>
<a href="#story-metrics" class="nav-link"><span class="nav-method method-GET">GET</span>Story Metrics</a>
<a href="#media-gallery" class="nav-link"><span class="nav-method method-GET">GET</span>Media Gallery</a>
</div>
Expand Down Expand Up @@ -2473,6 +2474,79 @@ function buildDocsPage() {
</div>
</section>

<section class="section" id="labels">
<div class="section-eyebrow">Surveys &amp; Stories</div>
<h2 class="section-title">Labels</h2>
<div class="section-desc">
<p>Labels (Story Labels) let an organisation code Stories and survey responses by theme, e.g. Housing or Improved confidence. You can list, create and edit the Labels of the organisations you belong to, and add them only to Stories you can see. Another organisation's Label, or a Story you can't see, returns 404.</p>
<p><code>privacy</code> is who may open the Label's page: <code>only_charity_colleagues</code> (default) or <code>everyone</code>.</p>
</div>
<div class="endpoint-list">
${endpointCard("GET", "/labels", "List your organisations' Labels", true, [
{ name: "charity_id", in: "query", type: "integer", required: false, desc: "Only this organisation's Labels" },
{ name: "search", in: "query", type: "string", required: false, desc: "Part of the name, case-insensitive" },
{ 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 Labels changed since then" }
], [
{ code: "200", cls: "response-2xx", desc: "<code>data</code>: each Label's <code>id</code>, <code>name</code>, <code>color</code>, <code>charity_id</code>, <code>user_id</code> and <code>privacy</code>, by name, in the paginated envelope" },
{ code: "401", cls: "response-4xx", desc: "Not authenticated" },
{ code: "422", cls: "response-4xx", desc: "<code>per_page</code> over 200" }
], "The Labels the Label popup on a Story offers.")}
${endpointCard("POST", "/labels", "Create a Label", true, [
{ name: "charity_id", in: "body", type: "integer", required: true, desc: "The organisation that owns the Label" },
{ name: "name", in: "body", type: "string", required: true, desc: "The theme, at most 255 characters" },
{ name: "color", in: "body", type: "string", required: false, desc: "Hex colour such as <code>#36ac9a</code>. Default <code>#3595d5</code>" },
{ name: "privacy", in: "body", type: "string", required: false, desc: "<code>only_charity_colleagues</code> or <code>everyone</code>" }
], [
{ code: "201", cls: "response-2xx", desc: "The Label" },
{ code: "401", cls: "response-4xx", desc: "Not authenticated" },
{ code: "403", cls: "response-4xx", desc: "An organisation you aren't in" },
{ code: "422", cls: "response-4xx", desc: "<code>errors</code>: a blank or long name, a bad colour or privacy" }
])}
${endpointCard("PATCH", "/labels/{id}", "Change a Label", true, [
{ name: "id", in: "path", type: "integer", required: true, desc: "The Label" },
{ name: "name", in: "body", type: "string", required: false, desc: "New name" },
{ name: "color", in: "body", type: "string", required: false, desc: "New hex colour" },
{ name: "privacy", in: "body", type: "string", required: false, desc: "<code>only_charity_colleagues</code> or <code>everyone</code>" },
{ name: "charity_id", in: "body", type: "integer", required: false, desc: "Move it to another of your organisations" }
], [
{ code: "200", cls: "response-2xx", desc: "The Label" },
{ code: "401", cls: "response-4xx", desc: "Not authenticated" },
{ code: "403", cls: "response-4xx", desc: "Moving it to an organisation you aren't in" },
{ code: "404", cls: "response-4xx", desc: "Not one of your organisations' Labels" },
{ code: "422", cls: "response-4xx", desc: "Invalid values" }
], "Only the fields you send change.")}
${endpointCard("GET", "/labels/{id}/stories", "List a Label's Stories", true, [
{ name: "id", in: "path", type: "integer", required: true, desc: "The Label" },
{ 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" }
], [
{ code: "200", cls: "response-2xx", desc: "<code>data</code>: each Story's <code>id</code>, <code>actual_created_at</code>, <code>created_at</code> and <code>labelled_at</code>, newest first, in the paginated envelope" },
{ 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 <code>GET /stories/{id}</code>.")}
${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" }
], [
{ code: "201", cls: "response-2xx", desc: "<code>story_id</code>, <code>label</code> and <code>label_ids</code> (your organisations' Labels now on the Story)" },
{ code: "401", cls: "response-4xx", desc: "Not authenticated" },
{ code: "404", cls: "response-4xx", desc: "A Story you can't see, or a Label that isn't your organisations'" },
{ code: "422", cls: "response-4xx", desc: "No <code>label_id</code>" }
], "Adding a Label the Story already has changes nothing.")}
${endpointCard("DELETE", "/stories/{story_id}/labels", "Take a Label off 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" }
], [
{ code: "200", cls: "response-2xx", desc: "<code>story_id</code>, <code>label</code> and <code>label_ids</code>" },
{ code: "401", cls: "response-4xx", desc: "Not authenticated" },
{ code: "404", cls: "response-4xx", desc: "A Story you can't see, or a Label that isn't your organisations'" },
{ code: "422", cls: "response-4xx", desc: "No <code>label_id</code>" }
])}
</div>
</section>

<!-- Media Gallery -->
<section class="section" id="media-gallery">
<div class="section-eyebrow">Surveys &amp; Stories</div>
Expand Down
Loading