Automating configuration changes using cURL
The example code below, shows how to automate the following functions:
- Initiate a stateful transaction
- Retrieve a list of all Watchpoints
- Create a new custom field
- Add a Watchpoint based on this custom field
- Commit the operations using cURL
To run the example, modify the HOST, USERNAME, and PASSWORD constants so that they correspond with your application settings.
Example code
$ curl -X POST -insecure "https://<HOST>/rest/configurationapi/transact
ionapi/1.0/transaction?usr=<USERNAME>&pwd=<PASSWORD>&tto=300&autoterminate=true"
<?xml version="1.0" encoding="utf-8"?>
<response>
<status result="success">
</status>
<result>
<tid>5</tid>
</result>
</response>
$ curl -X GET --insecure "https://<HOST>rest/configurationapi/watchpoi
ntapi/1.0/watchpoints?usr=<USERNAME>&pwd=<PASSWORD>&tid=5"
<?xml version="1.0" encoding="utf-8"?>
<response>
<status result="success">
</status>
<result>
<watchpoints>
<systemWatchpoint type="object" active="true" active-alarm="false" active-mib="true"/>
<systemWatchpoint type="page" active="true" active-alarm="false" active-mib="true"/>
<watchpoint id="11" type="page" active="true" active-alarm="false" active-mib="false"
filterselection="all">
<name><![CDATA[Function - Login Page]]></name>
<description><![CDATA[Watches users accessing any login page]]></description>
<filter active="true">
<description><![CDATA[Tracks the login page]]></description>
<name><![CDATA[Login page]]></name>
<expression><![CDATA[(url.stem_string contains "login" ignorecase)]]></expression>
</filter>
</watchpoint>
<watchpoint id="12" type="object" active="true" active-alarm="false" active-mib="false"
filterselection="all">
<name><![CDATA[Traffic - Secure (SSL)]]></name>
<description><![CDATA[All secure traffic]]></description>
<filter active="true">
<description><![CDATA[All secure traffic]]></description>
<name><![CDATA[Secure traffic]]></name>
<expression><![CDATA[(is_secure)]]></expression>
</filter>
</watchpoint>
<!-- complete list of Watchpoints was truncated for this example -->
</watchpoints>
</result>
</response>
$ echo '<customField active="true" entity="object" srcEntity="object" type="str
ing" policy="first-non-null" grammar="custom_test" export="x-custom-test" size=
"255"><name><![CDATA[Test CF]]></name><description><![CDATA[Description for Tes
t CF]]></description><extractions><defaultExtraction><source><sourceHost/></sou
rce></defaultExtraction></extractions></customField>' | curl -X POST -H 'Conten
t-type: text/xml' --insecure -d @- "https://<HOST>/rest/configurationa
pi/customfieldapi/1.0/customfield?usr=<USERNAME>&pwd=<PASSWORD>&tid=5"
<?xml version="1.0" encoding="utf-8"?>
<response>
<status result="success">
</status>
<result>
<customField id="19"/>
</result>
</response>
$ echo '<watchpoint type="object" active="true" active-alarm="false" active-mib
="false" filter-selection="all"><name><![CDATA[Test Wp]]></name><description><
![CDATA[Description for Test Wp]]></description><filter active="true"><name><![
CDATA[Test Wp filter]]></name><expression><![CDATA[(custom_test is "test" ignor
ecase)]]></expression></filter></watchpoint>' | curl -X POST -H 'Content-type:
text/xml' --insecure -d @- "https://<HOST>/rest/configurationapi/watch
pointapi/1.0/watchpoint?usr=<USERNAME>&pwd=<PASSWORd>&tid=5"
<?xml version="1.0" encoding="utf-8"?>
<response>
<status result="success">
</status>
<result>
<watchpoint id="101"/>
</result>
</response>
$ curl -X PUT --insecure "https://<HOST>/rest/configurationapi/transact
ionapi/1.0/transaction/5?usr=<USERNAME>&pwd=<PASSWORD>"
<?xml version="1.0" encoding="utf-8"?>
<response>
<status result="success">
</status>
</response>
ionapi/1.0/transaction?usr=<USERNAME>&pwd=<PASSWORD>&tto=300&autoterminate=true"
<?xml version="1.0" encoding="utf-8"?>
<response>
<status result="success">
</status>
<result>
<tid>5</tid>
</result>
</response>
$ curl -X GET --insecure "https://<HOST>rest/configurationapi/watchpoi
ntapi/1.0/watchpoints?usr=<USERNAME>&pwd=<PASSWORD>&tid=5"
<?xml version="1.0" encoding="utf-8"?>
<response>
<status result="success">
</status>
<result>
<watchpoints>
<systemWatchpoint type="object" active="true" active-alarm="false" active-mib="true"/>
<systemWatchpoint type="page" active="true" active-alarm="false" active-mib="true"/>
<watchpoint id="11" type="page" active="true" active-alarm="false" active-mib="false"
filterselection="all">
<name><![CDATA[Function - Login Page]]></name>
<description><![CDATA[Watches users accessing any login page]]></description>
<filter active="true">
<description><![CDATA[Tracks the login page]]></description>
<name><![CDATA[Login page]]></name>
<expression><![CDATA[(url.stem_string contains "login" ignorecase)]]></expression>
</filter>
</watchpoint>
<watchpoint id="12" type="object" active="true" active-alarm="false" active-mib="false"
filterselection="all">
<name><![CDATA[Traffic - Secure (SSL)]]></name>
<description><![CDATA[All secure traffic]]></description>
<filter active="true">
<description><![CDATA[All secure traffic]]></description>
<name><![CDATA[Secure traffic]]></name>
<expression><![CDATA[(is_secure)]]></expression>
</filter>
</watchpoint>
<!-- complete list of Watchpoints was truncated for this example -->
</watchpoints>
</result>
</response>
$ echo '<customField active="true" entity="object" srcEntity="object" type="str
ing" policy="first-non-null" grammar="custom_test" export="x-custom-test" size=
"255"><name><![CDATA[Test CF]]></name><description><![CDATA[Description for Tes
t CF]]></description><extractions><defaultExtraction><source><sourceHost/></sou
rce></defaultExtraction></extractions></customField>' | curl -X POST -H 'Conten
t-type: text/xml' --insecure -d @- "https://<HOST>/rest/configurationa
pi/customfieldapi/1.0/customfield?usr=<USERNAME>&pwd=<PASSWORD>&tid=5"
<?xml version="1.0" encoding="utf-8"?>
<response>
<status result="success">
</status>
<result>
<customField id="19"/>
</result>
</response>
$ echo '<watchpoint type="object" active="true" active-alarm="false" active-mib
="false" filter-selection="all"><name><![CDATA[Test Wp]]></name><description><
![CDATA[Description for Test Wp]]></description><filter active="true"><name><![
CDATA[Test Wp filter]]></name><expression><![CDATA[(custom_test is "test" ignor
ecase)]]></expression></filter></watchpoint>' | curl -X POST -H 'Content-type:
text/xml' --insecure -d @- "https://<HOST>/rest/configurationapi/watch
pointapi/1.0/watchpoint?usr=<USERNAME>&pwd=<PASSWORd>&tid=5"
<?xml version="1.0" encoding="utf-8"?>
<response>
<status result="success">
</status>
<result>
<watchpoint id="101"/>
</result>
</response>
$ curl -X PUT --insecure "https://<HOST>/rest/configurationapi/transact
ionapi/1.0/transaction/5?usr=<USERNAME>&pwd=<PASSWORD>"
<?xml version="1.0" encoding="utf-8"?>
<response>
<status result="success">
</status>
</response>
Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*