diff --git a/docs/api/synthetics/monitors/delete-monitor-api.asciidoc b/docs/api/synthetics/monitors/delete-monitor-api.asciidoc index 8730cc272a446..70861fcd60a36 100644 --- a/docs/api/synthetics/monitors/delete-monitor-api.asciidoc +++ b/docs/api/synthetics/monitors/delete-monitor-api.asciidoc @@ -8,9 +8,9 @@ Deletes one or more monitors from the Synthetics app. === {api-request-title} -`DELETE :/api/synthetics/monitors` +`DELETE :/api/synthetics/monitors/` -`DELETE :/s//api/synthetics/monitors` +`DELETE :/s//api/synthetics/monitors/` === {api-prereq-title} @@ -20,6 +20,26 @@ You must have `all` privileges for the *Synthetics* feature in the *{observabili You must have `all` privileges for the *Synthetics* feature in the *{observability}* section of the <>. + +[[delete-monitor-api-path-params]] +=== {api-path-parms-title} + +`config_id`:: +(Required, string) The ID of the monitor that you want to delete. + + +Here is an example of a DELETE request to delete a monitor by ID: + +[source,sh] +-------------------------------------------------- +DELETE /api/synthetics/monitors/monitor1-id +-------------------------------------------------- + +==== Bulk Delete Monitors + +You can delete multiple monitors by sending a list of config ids to a DELETE request to the `/api/synthetics/monitors` endpoint. + + [[monitors-delete-request-body]] ==== Request Body diff --git a/x-pack/plugins/observability_solution/synthetics/public/apps/synthetics/components/monitors_page/management/monitor_list_table/columns.tsx b/x-pack/plugins/observability_solution/synthetics/public/apps/synthetics/components/monitors_page/management/monitor_list_table/columns.tsx index a2970af2e98c7..1369fb086adab 100644 --- a/x-pack/plugins/observability_solution/synthetics/public/apps/synthetics/components/monitors_page/management/monitor_list_table/columns.tsx +++ b/x-pack/plugins/observability_solution/synthetics/public/apps/synthetics/components/monitors_page/management/monitor_list_table/columns.tsx @@ -200,7 +200,7 @@ export function useMonitorListColumns({ }, { 'data-test-subj': 'syntheticsMonitorCopyAction', - isPrimary: true, + isPrimary: false, name: (fields) => ( , - Record, + Record, + Record, { ids: string[] } > = () => ({ method: 'DELETE', - path: SYNTHETICS_API_URLS.SYNTHETICS_MONITORS, + path: SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/{id?}', validate: {}, validation: { request: { - body: schema.object({ - ids: schema.arrayOf(schema.string(), { - minSize: 1, - }), + body: schema.nullable( + schema.object({ + ids: schema.arrayOf(schema.string(), { + minSize: 1, + }), + }) + ), + params: schema.object({ + id: schema.maybe(schema.string()), }), }, }, handler: async (routeContext): Promise => { const { request, response } = routeContext; - const { ids } = request.body; + const { ids } = request.body || {}; + const { id: queryId } = request.params; const result: Array<{ id: string; deleted: boolean; error?: string }> = []; - await pMap(ids, async (id) => { + await pMap([...(ids ?? []), ...(queryId ? [queryId] : [])], async (id) => { try { const { errors, res } = await deleteMonitor({ routeContext,