Skip to main content

Hi All,

 

want to see what I’m doing wrong here… trying to follow the example here https://developer.automox.com/openapi/axconsole/operation/issueDeviceCommand/, to issue a command to a server so it can remediate itself, I want to do it one server at a time so it doesn’t take everyone down at once… I’m trying to use the command type “policy_{policy_id}_remediate”

 

 

so here is how I’m calling it through curl

 

 

curl -X POST

https://console.automox.com/api/servers/{server_id}/queues?o={org_id}

-H ‘Authorization: Bearer {api_key}’

-H ‘Content-Type: application/json’

-d '{

“command_type_name”: “policy_{policy_id}_remediate”

 

 

}’

 

 

I keep getting a {“errors”:p“The selected command type name is invalid.”]} error message…

 

 

am I calling it right? or is that for something else?

 

 

thanks,

Alan

 

Probably a dumb question, but sanity check here – we are substituting all the bracketed strings for actual values, right?




yes, if I do other command type such as “InstallAllUpdates” its coming back fine.


I was able to replicate your issue, getting a (400) bad request when attempting to use policy_{policy_id}_remediate as the docs state. GetOS returns a correct query, so something syntax related must be amiss in the docs. However, as a workaround, there is another query to accomplish your goal using https://developer.automox.com/openapi/axconsole/operation/executePolicy/

 

Here is a script that I use in our environment from @Tony

 


This script will apply multiple policies from your organization to a system. Say you always apply the same five policies to a newly built system, you could use this to apply those policies with one click to your new system. This will install any policy available in your organization regardless of whether it is attached to the group the system is in or not.
Make sure you’re not attempting to apply a macOS/Linux worklet or required software to a Windows device.
Just set the following:
$apiKey…

 


thank you so much Matt, that works!


This post gave me some hope till I tried the alternative. 400 bad request still. Note that I am able to lookup the server id, policy id, and org id using my API key so I know there is no issue with the headers or other URIs. I’ve tried getos too which does work.



PS C:\WINDOWS\system32> $FullURI

https://console.automox.com/api/policies/170420/action?o=12345&action=remediateServer&serverID=1093887



PS C:\WINDOWS\system32> $headers = @{

"Authorization" = "Bearer $key"

}

Invoke-RestMethod -Uri $FullURI -Method Post -Headers $headers

Invoke-RestMethod : The remote server returned an error: (400) Bad Request.

At line:4 char:1

+ Invoke-RestMethod -Uri $FullURI -Method Post -Headers $headers



For completeness, here is the original command starting with the server rather than policy.



PS C:\WINDOWS\system32> $EndPoint | select display_name,id,@{n="policyname";e={$_.policy_status.policy_name}},@{n="policyid";e={$_.policy_status.policy_id}},@{n="policytype";e={$_.policy_status.policy_type_name}}

display_name : CHMPTESTVM01

id : 1093887

policyname : Off Domain Patch All

policyid : 170420

policytype : patch



PS C:\WINDOWS\system32> $FullURI

https://console.automox.com/api/servers/1093887/queues?o=12345



PS C:\WINDOWS\system32> $headers

Name Value

---- -----

Content-Type application/json

Authorization Bearer 11111111-1111-1111-1111-111111111111



PS C:\WINDOWS\system32> $RequestBody

{

"command_type_name": "policy_170420_remediate"

}



PS C:\WINDOWS\system32> Invoke-RestMethod -Uri $FullURI -Method Post -Headers $headers -Body $RequestBody

Invoke-RestMethod : The remote server returned an error: (400) Bad Request.

I got this to work by modifying a script provided by the new purchase success team.



$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"

$headers.Add("Authorization", "Bearer $apiKey")

$FullURI = "https://console.automox.com/api/policies/$($policy.policy_id)/action?o=$orgID&action=remediateServer&serverId=$($ServerID)"

Invoke-RestMethod -Uri $FullURI -Method Post -Headers $headers

Reply