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
211 changes: 211 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ info:

> **Multi-user integrations:** If activity must be attributed to specific users, authenticate separately per user. A single Organisation Admin token is acceptable when attribution to one admin is sufficient.

### Organisation API keys
A custom integration that works for one Organisation should use an **API key** instead of a person's own token. An Organisation Admin creates one in Makerble under **Data In & Out → Integrations → API keys** (or with `POST /api_keys`). Send it on every request as:

```
Authorization: Bearer mk_live_...
```

A key belongs to one Organisation and acts as the colleague chosen when it was created: it can see and do only what they can, in that Organisation only. It can call the same endpoints as a connected app (OAuth), and gets `403` with `not_available_to_connected_apps` from any other. If the colleague leaves the Organisation, or the key is revoked, requests get `401`. Calls made with an Organisation's API keys count towards its monthly API usage.

## Creating Users via the API
`POST /users` requires a separate API Key (`auth_code`). Request one at [api-key-request@makerble.com](mailto:api-key-request@makerble.com).

Expand Down Expand Up @@ -288,6 +297,10 @@ tags:
Seats per Colleague: which seat each colleague holds on each of an Organisation's current
Contracts, and changing one. A colleague's roles decide the lowest seat (Billing Role) they
need on Role-based Pricing. Only the Organisation's admins can change seats.
- name: API keys
description: |
Keys an Organisation's admins create for the custom integrations they build. Each key belongs
to one Organisation and acts as one of its colleagues. See "Organisation API keys" above.
- name: Webhooks
description: |
HTTPS endpoints an Organisation's admins register to receive signed events when
Expand Down Expand Up @@ -11771,6 +11784,121 @@ paths:
"404":
$ref: '#/components/responses/NotFound'

/api_keys:
get:
tags: [API keys]
summary: List an Organisation's API keys
description: |
The Organisation's (Charity's) API keys, including revoked ones, without their secrets. Each key
shows the start of its secret (`secret_hint`) so it can be recognised. Only the Organisation's
admins can manage API keys (otherwise `403`). These endpoints need a person's own token: an API
key or a connected app gets `403`, so a key can't create or revoke keys.
operationId: listApiKeys
security: [{tokenAuth: []}]
parameters:
- name: charity_id
in: query
required: true
schema:
type: integer
description: The Organisation (Charity) ID
- $ref: '#/components/parameters/Page'
- $ref: '#/components/parameters/PerPage'
- $ref: '#/components/parameters/LastSyncDatetime'
responses:
"200":
description: Paginated list of API keys
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedApiKeys'
"401":
$ref: '#/components/responses/Unauthorized'
"403":
$ref: '#/components/responses/ForbiddenError'

post:
tags: [API keys]
summary: Create an API key
description: |
Creates a key for a custom integration. It acts as `user_id`, who must be a colleague in the
Organisation (a User with a role in it; see `GET /users`), and can see and do only what they can.
The response includes the key itself in `secret`, which is shown only this once: store it
somewhere safe. Send it as `Authorization: Bearer <secret>`.
operationId: createApiKey
security: [{tokenAuth: []}]
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ApiKeyRequest'
example:
charity_id: 913
api_key:
name: "Finance dashboard"
user_id: 4521
responses:
"201":
description: Key created, with its secret
headers:
Location:
description: Full address of the new key, e.g. `https://app.makerble.com/api/v2/api_keys/42`
schema:
type: string
format: uri
content:
application/json:
schema:
$ref: '#/components/schemas/ApiKeyWithSecret'
"401":
$ref: '#/components/responses/Unauthorized'
"403":
$ref: '#/components/responses/ForbiddenError'
"422":
$ref: '#/components/responses/UnprocessableEntity'

/api_keys/{id}:
parameters:
- $ref: '#/components/parameters/ResourceId'
get:
tags: [API keys]
summary: Get an API key
description: The key, without its secret. Another Organisation's key answers `404`.
operationId: getApiKey
security: [{tokenAuth: []}]
responses:
"200":
description: The key, without its secret
content:
application/json:
schema:
$ref: '#/components/schemas/ApiKey'
"401":
$ref: '#/components/responses/Unauthorized'
"404":
$ref: '#/components/responses/NotFound'

delete:
tags: [API keys]
summary: Revoke an API key
description: |
Revokes the key straight away: requests made with it get `401` from then on. This can't be
undone. The key stays in the list, with `active: false` and `revoked_at` set.
operationId: revokeApiKey
security: [{tokenAuth: []}]
responses:
"200":
description: The revoked key
content:
application/json:
schema:
$ref: '#/components/schemas/ApiKey'
"401":
$ref: '#/components/responses/Unauthorized'
"404":
$ref: '#/components/responses/NotFound'

/webhook_endpoints:
get:
tags: [Webhooks]
Expand Down Expand Up @@ -12238,6 +12366,12 @@ components:
description: |
Long-lived token from `POST /users/sign_in`. Does not expire.
Must be accompanied by `X-User-Email` header.
apiKeyAuth:
type: http
scheme: bearer
description: |
An Organisation API key (`mk_live_...`), sent as `Authorization: Bearer mk_live_...`. It acts
as the colleague chosen when it was created, in its Organisation only. See "Organisation API keys" above.
submissionBearerAuth:
type: http
scheme: bearer
Expand Down Expand Up @@ -18809,6 +18943,83 @@ components:
items:
$ref: '#/components/schemas/SeatColleague'

ApiKey:
type: object
properties:
id:
type: integer
charity_id:
type: integer
description: The Organisation (Charity) the key belongs to
name:
type: string
example: "Finance dashboard"
secret_hint:
type: string
description: The start of the key, to recognise it by. The rest is never shown again.
example: "mk_live_Ab12"
user_id:
type: integer
description: The colleague the key acts as
created_by_id:
type: integer
nullable: true
last_used_at:
type: string
format: date-time
nullable: true
revoked_at:
type: string
format: date-time
nullable: true
active:
type: boolean
description: false once revoked
created_at:
type: string
format: date-time
updated_at:
type: string
format: date-time

ApiKeyWithSecret:
allOf:
- $ref: '#/components/schemas/ApiKey'
- type: object
properties:
secret:
type: string
description: The key itself. Shown only in the response that created it.
example: "mk_live_Ab12Cd34Ef56Gh78Ij90Kl12Mn34Op56"

ApiKeyRequest:
type: object
required: [charity_id, api_key]
properties:
charity_id:
type: integer
description: The Organisation (Charity) ID
api_key:
type: object
required: [name, user_id]
properties:
name:
type: string
description: What the key is for
user_id:
type: integer
description: The colleague the key acts as

PaginatedApiKeys:
allOf:
- $ref: '#/components/schemas/PaginationEnvelope'
- type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/ApiKey'

PaginatedWebhookEndpoints:
allOf:
- $ref: '#/components/schemas/PaginationEnvelope'
Expand Down
49 changes: 49 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ function buildDocsPage() {
<div class="nav-section">
<div class="nav-section-label">Integrations</div>
<a href="#webhooks" class="nav-link"><span class="nav-method method-POST">POST</span>Webhooks</a>
<a href="#api-keys" class="nav-link"><span class="nav-method method-POST">POST</span>API keys</a>
<a href="#seats" class="nav-link"><span class="nav-method method-GET">GET</span>Seats</a>
</div>
<div class="nav-section">
Expand Down Expand Up @@ -1035,6 +1036,11 @@ function buildDocsPage() {
<span><strong>Multi-user integrations:</strong> If you need activity attributed to specific users, authenticate separately per user. A single Organisation Admin token is fine when attribution to a single admin is acceptable.</span>
</div>

<div class="callout callout-tip" style="margin-top:20px">
<span class="callout-icon">✓</span>
<span><strong>Organisation API keys:</strong> a custom integration that works for one Organisation should use an <a href="#api-keys">API key</a> instead of a person's token. Send it as <code>Authorization: Bearer mk_live_…</code> on every request, with no <code>X-User-Email</code> or <code>X-User-Token</code>.</span>
</div>

<div class="endpoint-list">
<div class="endpoint-card">
<div class="endpoint-header" onclick="toggle(this)">
Expand Down Expand Up @@ -3455,6 +3461,49 @@ function buildDocsPage() {
</div>
</section>

<!-- API keys -->
<section class="section" id="api-keys">
<div class="section-eyebrow">Integrations</div>
<h2 class="section-title">API keys</h2>
<div class="section-desc">
<p>An API key lets a custom integration call the API for one Organisation without using a person's own token. An Organisation Admin creates one in Makerble under <strong>Data In &amp; Out → Integrations → API keys</strong>, or with <code>POST /api_keys</code> below. The key itself (<code>mk_live_…</code>) is shown only once, when it is created.</p>
<p><strong>Using a key:</strong> send <code>Authorization: Bearer mk_live_…</code> on every request. The key acts as the colleague chosen when it was created: it can see and do only what they can, in its Organisation only. It can call the same endpoints as a connected app (OAuth); any other answers <code>403</code> with <code>not_available_to_connected_apps</code>. A revoked key, or one whose colleague has left the Organisation, gets <code>401</code>. Calls made with an Organisation's API keys count towards its monthly API usage.</p>
<p><strong>Managing keys:</strong> only the Organisation's admins can list, create and revoke its keys, and only with their own <code>X-User-Email</code> and <code>X-User-Token</code>: an API key or a connected app can't create or revoke keys.</p>
</div>
<div class="endpoint-list">
${endpointCard("GET", "/api_keys", "List an Organisation's API keys", true, [
{ name: "charity_id", type: "integer", required: true, desc: "The Organisation ID" },
{ name: "page", type: "integer", required: false, desc: "Page number" },
{ name: "per_page", type: "integer", required: false, desc: "Records per page" },
{ name: "last_synced_datetime", type: "string", required: false, desc: "ISO 8601 incremental sync" }
], [
{ code: "200", cls: "response-2xx", desc: "Paginated list of keys, including revoked ones, without secrets" },
{ code: "403", cls: "response-4xx", desc: "Not an admin of this Organisation, or called with an API key or connected app" }
])}
${endpointCard("POST", "/api_keys", "Create an API key", true, [
{ name: "charity_id", in: "body", type: "integer", required: true, desc: "The Organisation ID" },
{ name: "api_key[name]", in: "body", type: "string", required: true, desc: "What the key is for" },
{ name: "api_key[user_id]", in: "body", type: "integer", required: true, desc: "The colleague the key acts as (a User in the Organisation)" }
], [
{ code: "201", cls: "response-2xx", desc: "Created — includes the key in secret, shown only this once" },
{ code: "403", cls: "response-4xx", desc: "Not an admin of this Organisation" },
{ code: "422", cls: "response-4xx", desc: "No name, or the user isn't a colleague in the Organisation" }
])}
${endpointCard("GET", "/api_keys/{id}", "Get an API key", true, [
{ name: "id", in: "path", type: "integer", required: true, desc: "API key ID" }
], [
{ code: "200", cls: "response-2xx", desc: "The key, without its secret" },
{ code: "404", cls: "response-4xx", desc: "Not found, or not an admin of its Organisation" }
])}
${endpointCard("DELETE", "/api_keys/{id}", "Revoke an API key", true, [
{ name: "id", in: "path", type: "integer", required: true, desc: "API key ID" }
], [
{ code: "200", cls: "response-2xx", desc: "The revoked key: it stops working at once, and this can't be undone" },
{ code: "404", cls: "response-4xx", desc: "Not found, or not an admin of its Organisation" }
])}
</div>
</section>

<!-- Webhooks -->
<section class="section" id="webhooks">
<div class="section-eyebrow">Integrations</div>
Expand Down
Loading