diff --git a/openapi.yaml b/openapi.yaml index 36271c1..f713d79 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -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). @@ -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 @@ -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 `. + 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] @@ -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 @@ -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' diff --git a/server.js b/server.js index a604ccd..e7568ae 100644 --- a/server.js +++ b/server.js @@ -966,6 +966,7 @@ function buildDocsPage() { +
+ ✓ + Organisation API keys: a custom integration that works for one Organisation should use an API key instead of a person's token. Send it as Authorization: Bearer mk_live_… on every request, with no X-User-Email or X-User-Token. +
+
@@ -3455,6 +3461,49 @@ function buildDocsPage() {
+ +
+
Integrations
+

API keys

+
+

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 Data In & Out → Integrations → API keys, or with POST /api_keys below. The key itself (mk_live_…) is shown only once, when it is created.

+

Using a key: send Authorization: Bearer mk_live_… 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 403 with not_available_to_connected_apps. A revoked key, or one whose colleague has left the Organisation, gets 401. Calls made with an Organisation's API keys count towards its monthly API usage.

+

Managing keys: only the Organisation's admins can list, create and revoke its keys, and only with their own X-User-Email and X-User-Token: an API key or a connected app can't create or revoke keys.

+
+
+ ${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" } + ])} +
+
+
Integrations