diff --git a/openapi.yaml b/openapi.yaml index b4e0663..b6bb595 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -16104,6 +16104,85 @@ paths: "422": description: "`{error}`: it has already been reviewed" + /contact_merges: + get: + tags: [Suggested Merges] + summary: List merges that can be undone + description: | + The Contacts merged into others in an Organisation that can still be unmerged, as listed in + each Contact's Merged with box. Newest first. Organisation Admins only. + operationId: listContactMerges + security: [{tokenAuth: []}] + parameters: + - name: charity_id + in: query + required: true + schema: + type: integer + description: The Organisation (Charity) ID + - name: beneficiary_id + in: query + schema: + type: integer + description: Only merges into this Contact (the Contact that was kept) + - $ref: '#/components/parameters/Page' + - $ref: '#/components/parameters/PerPage' + - $ref: '#/components/parameters/LastSyncDatetime' + responses: + "200": + description: Paginated list of merges + content: + application/json: + example: + page: 1 + page_size: 1 + page_count: 1 + total_count: 1 + data: + - id: 311 + contact: { id: 101, name: Grace Mensah } + merged_contact: { id: 188, name: Grace Mensah } + merged_by: { id: 5, name: Asha Patel } + merged_at: "2026-11-20T10:15:00Z" + "401": + $ref: '#/components/responses/Unauthorized' + "403": + description: The user isn't an Organisation Admin of the Organisation + "404": + $ref: '#/components/responses/NotFound' + "422": + description: "`{errors}`: last_synced_datetime isn't a date and time" + + /contact_merges/{id}/unmerge: + post: + tags: [Suggested Merges] + summary: Unmerge two Contacts + description: | + Undoes a merge, as Unmerge does on the Contact's profile. The merged-away Contact comes back + with its own details and Surveys. Organisation Admins only. A merge the user can't undo, + or one already undone, returns 404. + operationId: unmergeContacts + security: [{tokenAuth: []}] + parameters: + - name: id + in: path + required: true + schema: + type: integer + description: The merge ID, from GET /contact_merges + responses: + "200": + description: Unmerged + content: + application/json: + example: + contact: { id: 101, name: Grace Mensah } + restored_contact: { id: 188, name: Grace Mensah } + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + /duplicate_contacts: get: tags: [Duplicate Contacts] diff --git a/server.js b/server.js index 96f5fb8..68e5bdd 100644 --- a/server.js +++ b/server.js @@ -3719,7 +3719,7 @@ function buildDocsPage() { { name: "id", type: "integer", required: true, in: "path", desc: "The Suggested Merge ID" }, { name: "winner_id", type: "integer", required: false, in: "body", desc: "The Contact to keep. Default: the one created first" } ], [ - { code: "202", cls: "response-2xx", desc: "Merging has begun: suggested_merge (now merged) and merge_request_ids. Undo with Unmerge on the Merge Contacts page" }, + { code: "202", cls: "response-2xx", desc: "Merging has begun: suggested_merge (now merged) and merge_request_ids. Undo with POST /contact_merges/{id}/unmerge" }, { code: "404", cls: "response-4xx", desc: "Not a suggestion you can see" }, { code: "422", cls: "response-4xx", desc: "{error}: the Contact to keep isn't one of its Contacts, or it has already been reviewed" } ])} @@ -3730,6 +3730,23 @@ function buildDocsPage() { { code: "404", cls: "response-4xx", desc: "Not a suggestion you can see" }, { code: "422", cls: "response-4xx", desc: "{error}: it has already been reviewed" } ])} + ${endpointCard("GET", "/contact_merges", "List merges that can be undone", true, [ + { name: "charity_id", type: "integer", required: true, desc: "The Organisation ID" }, + { name: "beneficiary_id", type: "integer", required: false, desc: "Only merges into this Contact" }, + { name: "page", type: "integer", required: false, desc: "Page number" }, + { name: "per_page", type: "integer", required: false, desc: "Records per page (at most 200)" }, + { name: "last_synced_datetime", type: "string", required: false, desc: "ISO 8601: merges made after this time" } + ], [ + { code: "200", cls: "response-2xx", desc: "Paginated list: id, contact {id, name}, merged_contact {id, name}, merged_by {id, name}, merged_at, newest first" }, + { code: "403", cls: "response-4xx", desc: "You aren't an Organisation Admin of the Organisation" }, + { code: "422", cls: "response-4xx", desc: "last_synced_datetime isn't a date and time" } + ])} + ${endpointCard("POST", "/contact_merges/{id}/unmerge", "Unmerge two Contacts", true, [ + { name: "id", type: "integer", required: true, in: "path", desc: "The merge ID" } + ], [ + { code: "200", cls: "response-2xx", desc: "contact (kept) and restored_contact, both {id, name}" }, + { code: "404", cls: "response-4xx", desc: "Not a merge you can undo, or already undone" } + ])} ${endpointCard("GET", "/merge_rules", "List an Organisation's Merge Rules", true, [ { name: "charity_id", type: "integer", required: true, desc: "The Organisation ID" }, { name: "page", type: "integer", required: false, desc: "Page number" }, @@ -3822,7 +3839,7 @@ function buildDocsPage() { { name: "contact_ids", type: "array", required: true, in: "body", desc: "At least two Contacts" }, { name: "winner_id", type: "integer", required: false, in: "body", desc: "The Contact to keep. Default: the one created first" } ], [ - { code: "202", cls: "response-2xx", desc: "Merging has begun: {winner_id, merge_request_ids, message}. Undo with Unmerge on the Merge Contacts page" }, + { code: "202", cls: "response-2xx", desc: "Merging has begun: {winner_id, merge_request_ids, message}. Undo with POST /contact_merges/{id}/unmerge" }, { code: "403", cls: "response-4xx", desc: "You can't merge Contacts in the Organisation" }, { code: "422", cls: "response-4xx", desc: "{error}: fewer than two Contacts, one you can't merge, or a Contact to keep that isn't one of them" } ])}