Change bes computer setting with curl

Hi,

How can i use the following curl command to edit a computer setting?

curl -X GET --insecure --user “user/password” https://Server:12345/api/computer/{computer ID}/setting/{_BESClient_Download_MinimumDiskFreeMB}

Can POST or PUT be used for this by adding the value at the end of the curl command something like this?

curl -X POST --insecure --user “user/password” https://Server:port/api/computer/{computer ID}/setting/{_BESClient_Download_MinimumDiskFreeMB}/value/{200}

Thanks

I haven’t done this myself, but it seems like you would do a put or post request, but with a request body that has the value you want to update it to.

See the documentation here: https://developer.bigfix.com/rest-api/api/computer.html

The api endpoint is: api/computer/{computer id}/setting/{setting name}

You would do a get request to get an example result, then generally you can edit that result with what you want to change the value to, then post it back to the same endpoint you did the get request to and it should make the change.

You can also technically do this with an action without using this specific method, which allow you to set multiple settings at once on multiple computers at once. If you that is your desired effect, then it would be better to use an action.

As an example, I did a GET request on the following API:

https://localhost:52311/api/computer/0000000/setting/_BESClient_Log_Days

and got the following answer:

<?xml version='1.0' encoding='utf-8'?>
<BESAPI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BESAPI.xsd">
        <ComputerSettings Resource="https://localhost:52311/api/computer/0000000/setting/_BESClient_Log_Days">
                <Setting Resource="https://localhost:52311/api/computer/0000000/setting/_BESClient_Log_Days">
                        <Name>_BESClient_Log_Days</Name>
                        <Value>30</Value>
                </Setting>
        </ComputerSettings>
</BESAPI>

Then to change this setting, you would take this exact XML, but change what is within the <Value>30</Value> tag and change it to whatever you want. Then you should be able to POST this back to this same API to change it, or POST it to any other computer API endpoint you wish to make the same change.

This process does require that the setting already exist that you wish to change, but once you get this XML back, you can use it as a template to change both the name and the value of the setting you wish to change.

Here is an example mustache / handlebars template:

<?xml version='1.0' encoding='utf-8'?>
<BESAPI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BESAPI.xsd">
        <ComputerSettings Resource="https://{{{root_server}}}:52311/api/computer/0000000/setting/{{{setting_name}}}">
                <Setting Resource="https://{{{root_server}}}:52311/api/computer/0000000/setting/{{{setting_name}}}">
                        <Name>{{{setting_name}}}</Name>
                        <Value>{{{setting_value}}}</Value>
                </Setting>
        </ComputerSettings>
</BESAPI>

In most cases, I find this to be the easiest way to work with the BigFix REST API… get an example using a GET request, then turn that into the desired values you wish to change and make a POST request to make the change. Alternatively you can do a GET request and use that result and turn it into a template to use in a generic case instead of a specific case, and then you could build a function to make this change automatically with the correct inputs.

FYI, there is a python library for working with the BigFix REST API that I plan to add more generic functionality like this in the future: https://github.com/jgstew/besapi

1 Like

When I used the api/computer/{computer id}/setting/{setting name} endpoint along with the xml file generated with the GET method as you suggested the command output returned an action ID. Worked like a charm.

Thanks JG!

1 Like