How to set computer property via REST API

Hello,
I’m strugling to set computer property using REST API. I’m able to get property of the computer but I’m not able set it (no problem to set it via console manually however).

I’m using Rested to send test XML doc (see below) to server and I’m getting 401.

Any hints / tips / examples are welcome.

Thanks

<?xml version="1.0" encoding="UTF-8"?>
<BESAPI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BESAPI.xsd">
    <ComputerSettings Resource="https://server:port/api/computer/computer_id/setting/_my_property">
        <Setting Resource="https://server:port/api/computer/computer_id/setting/_my_property">
            <Name>
                _my_property
            </Name>
            <Value>
                True
            </Value>
        </Setting>
    </ComputerSettings>
</BESAPI>

POST this to https://server:port/api/computer/computer_id/settings

(obviously replace “server”, “port” and “computer_id” with the appropriate values)

<?xml version="1.0" encoding="UTF-8"?>
<BESAPI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BESAPI.xsd">
  <ComputerSettings>
    <Setting>
       <Name>_my_property</Name>
       <Value>True</Value>
    </Setting>
  </ComputerSettings>
</BESAPI>

401 means “not authorized”. Try with a user with masteroperator authorization

1 Like

Hello mikelbeck,
this gives me 401 as well…

Hi Matthias,
as I have pointed out I’m using the very same account I’m using in console and there is no problem to set computer property. The same account is used to add computers to manual group(s) and query computer settings using REST API. I have not seen any example for setting the property on computer and documentation does not say much :confused: (https://developer.bigfix.com/rest-api/api/computer.html)

did you authenticate to the REST API before POST?

What you mean by “authenticate”? If you mean standard authentication then of course I’m authenticated - I would not be able to eg add computers to manual group - as I pointed out in my last comment - if I would not be authenticated (well I would not be able to use the API at all). If you mean that there is some additional authentication required then I’m not aware of it.

I took your XML block and modified with my Root Server URL and Computer ID.

<?xml version="1.0" encoding="UTF-8"?>
<BESAPI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BESAPI.xsd">
    <ComputerSettings Resource="https://server:port/api/computer/1086875885/setting/_my_property">
        <Setting Resource="https://bfwinroot.gbl.tx.usa:52311/api/computer/1086875885/setting/_my_property">
            <Name>
                _my_property
            </Name>
            <Value>
                True
            </Value>
        </Setting>
    </ComputerSettings>
</BESAPI>

curl -s -k --cookie-jar cookie.txt -u BFAdmin:Passw0rd https://bfwinroot.gbl.tx.usa:52311/api/login

curl -s -k -b cookie.txt --data @setting2.xml -X POST https://bfwinroot.gbl.tx.usa:52311/api/computer/1086875885/settings

<?xml version="1.0" encoding="UTF-8"?>
<BESAPI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BESAPI.xsd">
        <Action Resource="https://bfwinroot.gbl.tx.usa:52311/api/action/65218">
                <ID>65218</ID>
        </Action>
</BESAPI>

Thanks @gbl888 - this works. I guess that problem was not with login but with the format of the settings XML file because I can use it now without /login first and just use username:password combination. On the first sight the xml you have posted does not differ from mine however :confused: