diff --git a/frontend/pages/hosts/details/cards/Scripts/Scripts.tsx b/frontend/pages/hosts/details/cards/Scripts/Scripts.tsx index 997949b926..4c94a499c7 100644 --- a/frontend/pages/hosts/details/cards/Scripts/Scripts.tsx +++ b/frontend/pages/hosts/details/cards/Scripts/Scripts.tsx @@ -67,7 +67,10 @@ const Scripts = ({ hostId, page = 0, isHostOnline, router }: IScriptsProps) => { break; case "run": try { - await scriptsAPI.runScript(script.script_id); + await scriptsAPI.runScript({ + host_id: hostId, + script_id: script.script_id, + }); refetchScriptsData(); } catch (e) { const error = e as AxiosResponse; diff --git a/frontend/services/entities/scripts.ts b/frontend/services/entities/scripts.ts index 9fc555112d..a89f078b02 100644 --- a/frontend/services/entities/scripts.ts +++ b/frontend/services/entities/scripts.ts @@ -72,6 +72,27 @@ export interface IHostScriptsResponse { }; } +/** + * Request body for POST /scripts/run + * + * https://fleetdm.com/docs/rest-api/rest-api#run-script-asynchronously + */ +export interface IScriptRunRequest { + host_id: number; + script_id: number; // script_id is not required by the API currently, but we require it here to ensure it is always provided + // script_contents: string; // script_contents is only supported for the CLI currently +} + +/** + * Response body for POST /scripts/run + * + * https://fleetdm.com/docs/rest-api/rest-api#run-script-asynchronously + */ +export interface IScriptRunResponse { + host_id: number; + execution_id: string; +} + export default { getHostScripts(id: number, page?: number) { const { HOST_SCRIPTS } = endpoints; @@ -126,8 +147,8 @@ export default { return sendRequest("GET", SCRIPT_RESULT(executionId)); }, - runScript(id: number) { + runScript(request: IScriptRunRequest): Promise { const { SCRIPT_RUN } = endpoints; - return sendRequest("POST", SCRIPT_RUN, { script_id: id }); + return sendRequest("POST", SCRIPT_RUN, request); }, };