{"id":74747,"date":"2023-06-05T13:12:17","date_gmt":"2023-06-05T17:12:17","guid":{"rendered":"https:\/\/jumpcloud.com\/?post_type=support&p=74747"},"modified":"2023-06-05T13:12:17","modified_gmt":"2023-06-05T17:12:17","slug":"use-command-triggers","status":"publish","type":"support","link":"https:\/\/jumpcloud.com\/support\/use-command-triggers","title":{"rendered":"Use Command Triggers"},"content":{"rendered":"\n
To use command triggers, enter a trigger name associated with a command that you create in DEVICE MANAGEMENT<\/strong> > Commands<\/strong>, and then save the command.<\/p>\n\n\n\n When JumpCloud receives a webhook containing the trigger name, JumpCloud will automatically execute any command with that trigger name, in parallel, across all the servers defined in the saved commands.<\/p>\n\n\n\n This lets you automate some very powerful actions on your network, such as:<\/p>\n\n\n\n \u2026 and much, much more.<\/p>\n\n\n\n To execute a trigger, form a webhook request as follows (shown below as a curl command, run from bash and as a PowerShell command):<\/p>\n\n\n\n !\/bin\/bash Upon receipt of this request, assuming the API key is correct and that one or more commands are set to run based on the trigger name “myTriggerName”, JumpCloud will start all commands that match the trigger name “myTriggerName”.<\/p>\n\n\n\n To obtain your API key, select your user name in the upper right corner of the JumpCloud console, and select My API Key<\/strong>.<\/p>\n\n\n\n JumpCloud allows you to post a JSON object with a trigger. JumpCloud will provide each top level data object as an environment variable to the triggered command. This allows you to do things like:<\/p>\n\n\n\n \u2026 and much more.<\/p>\n\n\n\n To send data to a Trigger, you change the webhook call to include as part of the body of the POST request, a well-formatted JSON object.<\/p>\n\n\n\n !\/bin\/bash For example, sending:<\/p>\n\n\n\n { “srcip”:”192.168.2.32″, “test”:{ “bob”:”1″, “jane”:”3″} }<\/p>\n<\/div><\/div>\n\n\n\n Results in the following environment variables in your command:<\/p>\n\n\n\n test=”[object Object]” To use command triggers, enter a trigger name associated with a command that you create in DEVICE MANAGEMENT > Commands, […]<\/p>\n","protected":false},"author":206,"featured_media":0,"template":"","meta":{"_acf_changed":false,"_oasis_is_in_workflow":0,"_oasis_original":0,"_oasis_task_priority":"","inline_featured_image":false,"footnotes":""},"support_category":[2895,2852],"support_tag":[],"coauthors":[2842],"acf":[],"yoast_head":"\n\n
\n
Basic Trigger Execution<\/h2>\n\n\n\n
jumpCloudAPIKey=””
triggerName=”myTriggerName”
curl –silent \\
-X ‘POST’ \\
-H “x-api-key: ${jumpCloudAPIKey}” \\
“https:\/\/console.jumpcloud.com\/api\/command\/trigger\/${triggerName}”
PS \/PowerShell>
$APIkey = ‘jumpCloudAPIKey’
$triggerName = ‘myTriggerName’
$TriggerURL = “https:\/\/console.jumpcloud.com\/api\/command\/trigger\/$triggerName”
$hdrs = @{}
$hdrs.Add(“Accept”,”application\/json”)
$hdrs.Add(“X-API-KEY”,”$APIkey”)
Invoke-RestMethod -Method POST -Uri $TriggerURL -Header $hdrs<\/p>\n<\/div><\/div>\n\n\n\nSending Data with a Trigger<\/h2>\n\n\n\n
\n
jumpCloudAPIKey=”my_user_API_key”
triggerName=”myTriggerName”
curl –silent \\
-X ‘POST’ \\
-H “x-api-key: ${jumpCloudAPIKey}” \\
-H ‘Content-Type: application\/json’ \\
-d ‘{ “srcip”:”192.168.2.32″ }’ \\
“https:\/\/console.jumpcloud.com\/api\/command\/trigger\/${triggerName}”
Remember that only the top level objects are provided to the command, any sub-objects or arrays will be sent as “[object Object]”.<\/p>\n<\/div><\/div>\n\n\n\n
srcip=”192.168.2.32″<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"