| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 | --:api: execute-watch:request: ExecuteWatchRequest:response: ExecuteWatchResponse--[role="xpack"][id="{upid}-{api}"]=== Execute watch APIThe execute watch API allows clients to immediately execute a watch, either onethat has been previously added via the {ref}/watcher-api-put-watch.html[createor update watch API] or inline as part of the request.[id="{upid}-{api}-request-by-id"]==== Execute by idSubmit the following request to execute a previously added watch:["source","java",subs="attributes,callouts,macros"]---------------------------------------------------include-tagged::{doc-tests-file}[x-pack-execute-watch-by-id]---------------------------------------------------<1> Alternative input for the watch to use in json format<2> Set the mode for action "action1" to SIMULATE<3> Record this execution in watcher history<4> Execute the watch regardless of the watch's condition<5> Set the trigger data for the watch in json format<6> Enable debug mode[id="{upid}-{api}-response-by-id"]==== Execute by id responseThe returned `Response` contains details of the execution:["source","java",subs="attributes,callouts,macros"]---------------------------------------------------include-tagged::{doc-tests-file}[x-pack-execute-watch-by-id-response]---------------------------------------------------<1> The record ID for this execution<2> The execution response as a java `Map`<3> Extract information from the response map using `ObjectPath`[id="{upid}-{api}-response-by-id-async"]==== Asynchronous execution by idThis request can be executed asynchronously:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[x-pack-execute-watch-by-id-execute-async]--------------------------------------------------<1> The `ExecuteWatchRequest` to execute and the `ActionListener` to use whenthe execution completesThe asynchronous method does not block and returns immediately. Once it iscompleted the `ActionListener` is called back using the `onResponse` methodif the execution successfully completed or using the `onFailure` method ifit failed.A typical listener for `ExecuteWatchResponse` looks like:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[x-pack-execute-watch-by-id-execute-listener]--------------------------------------------------<1> Called when the execution is successfully completed. The response isprovided as an argument<2> Called in case of failure. The raised exception is provided as an argument[id="{upid}-{api}-request-inline"]==== Execute inlineSubmit the following request to execute a watch defined as part of the request:["source","java",subs="attributes,callouts,macros"]---------------------------------------------------include-tagged::{doc-tests-file}[x-pack-execute-watch-inline]---------------------------------------------------<1> Alternative input for the watch to use in json format<2> Set the mode for action "action1" to SIMULATE<3> Execute the watch regardless of the watch's condition<4> Set the trigger data for the watch in json format<5> Enable debug modeNote that inline watches cannot be recorded.The response format and asynchronous execution methods are the same as for theExecute Watch by ID API.
 |